Skip to content

Commit c5b69eb

Browse files
committed
Throw an error if Resend responds with an error
1 parent 2a07ea4 commit c5b69eb

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

internal-packages/emails/src/index.tsx

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,14 +127,21 @@ export class EmailClient {
127127

128128
async #sendEmail({ to, subject, react }: { to: string; subject: string; react: ReactElement }) {
129129
if (this.#client) {
130-
await this.#client.emails.send({
130+
const result = await this.#client.emails.send({
131131
from: this.#from,
132132
to,
133133
reply_to: this.#replyTo,
134134
subject,
135135
react,
136136
});
137137

138+
if (result.error) {
139+
console.error(
140+
`Failed to send email to ${to}, ${subject}. Error ${result.error.name}: ${result.error.message}`
141+
);
142+
throw new EmailError(result.error);
143+
}
144+
138145
return;
139146
}
140147

@@ -147,3 +154,11 @@ ${render(react, {
147154
`);
148155
}
149156
}
157+
158+
//EmailError type where you can set the name and message
159+
export class EmailError extends Error {
160+
constructor({ name, message }: { name: string; message: string }) {
161+
super(message);
162+
this.name = name;
163+
}
164+
}

0 commit comments

Comments
 (0)