diff --git a/internal-packages/emails/src/index.tsx b/internal-packages/emails/src/index.tsx index 3dc6c78eb5..8ad1a35b8e 100644 --- a/internal-packages/emails/src/index.tsx +++ b/internal-packages/emails/src/index.tsx @@ -127,7 +127,7 @@ export class EmailClient { async #sendEmail({ to, subject, react }: { to: string; subject: string; react: ReactElement }) { if (this.#client) { - await this.#client.emails.send({ + const result = await this.#client.emails.send({ from: this.#from, to, reply_to: this.#replyTo, @@ -135,6 +135,13 @@ export class EmailClient { react, }); + if (result.error) { + console.error( + `Failed to send email to ${to}, ${subject}. Error ${result.error.name}: ${result.error.message}` + ); + throw new EmailError(result.error); + } + return; } @@ -147,3 +154,11 @@ ${render(react, { `); } } + +//EmailError type where you can set the name and message +export class EmailError extends Error { + constructor({ name, message }: { name: string; message: string }) { + super(message); + this.name = name; + } +}