From bde2ae96bd463edd8c7a9e092452c33c03fa6844 Mon Sep 17 00:00:00 2001 From: Rob Cameron Date: Wed, 28 Aug 2024 17:25:47 -0700 Subject: [PATCH 1/2] Catch errors when studio is not running and mail tries to send --- packages/mailer/handlers/studio/src/index.ts | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/packages/mailer/handlers/studio/src/index.ts b/packages/mailer/handlers/studio/src/index.ts index 5eb7ad671bcd..bd0f53a8976c 100644 --- a/packages/mailer/handlers/studio/src/index.ts +++ b/packages/mailer/handlers/studio/src/index.ts @@ -27,11 +27,20 @@ export class StudioMailHandler extends AbstractMailHandler { sendOptions: MailSendOptionsComplete, handlerOptions?: HandlerOptions, ): Promise { - return this.nodemailerHandler.send( - renderedContent, - sendOptions, - handlerOptions, - ) + try { + return await this.nodemailerHandler.send( + renderedContent, + sendOptions, + handlerOptions, + ) + } catch (e: any) { + console.error( + '\nSent an email to the void! You can view this email during development\nwith Redwood Studio: `yarn rw studio`', + ) + console.error(' ' + e.message + '\n') + } + + return {} } internal() { From 30ab8bd73c579c52d55283a9b95222743b5b65d7 Mon Sep 17 00:00:00 2001 From: Josh GM Walker <56300765+Josh-Walker-GM@users.noreply.github.com> Date: Thu, 29 Aug 2024 01:52:13 +0100 Subject: [PATCH 2/2] cast to error over any --- packages/mailer/handlers/studio/src/index.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/mailer/handlers/studio/src/index.ts b/packages/mailer/handlers/studio/src/index.ts index bd0f53a8976c..1ee0c2e7fea7 100644 --- a/packages/mailer/handlers/studio/src/index.ts +++ b/packages/mailer/handlers/studio/src/index.ts @@ -33,11 +33,11 @@ export class StudioMailHandler extends AbstractMailHandler { sendOptions, handlerOptions, ) - } catch (e: any) { + } catch (e) { console.error( - '\nSent an email to the void! You can view this email during development\nwith Redwood Studio: `yarn rw studio`', + '\nSent an email to the void! You can view this email during development with Redwood Studio: `yarn rw studio`', ) - console.error(' ' + e.message + '\n') + console.error(' ' + (e as Error).message + '\n') } return {}