Skip to content

Commit 760887f

Browse files
committed
Adjust mail transport error handling
Gotta keep the linter happy :) Signed-off-by: Erin Allison <eallison@andrettikarting.com>
1 parent 7c00e28 commit 760887f

File tree

2 files changed

+49
-35
lines changed

2 files changed

+49
-35
lines changed

internal-packages/emails/src/transports/aws-ses.ts

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,15 @@ export class AwsSesMailTransport implements MailTransport {
3131
html: render(react),
3232
});
3333
}
34-
catch (error: Error) {
35-
console.error(
36-
`Failed to send email to ${to}, ${subject}. Error ${error.name}: ${error.message}`
37-
);
38-
throw new EmailError(error);
34+
catch (error) {
35+
if (error instanceof Error) {
36+
console.error(
37+
`Failed to send email to ${to}, ${subject}. Error ${error.name}: ${error.message}`
38+
);
39+
throw new EmailError(error);
40+
} else {
41+
throw error;
42+
}
3943
}
4044
}
4145

@@ -49,11 +53,15 @@ export class AwsSesMailTransport implements MailTransport {
4953
text: text,
5054
});
5155
}
52-
catch (error: Error) {
53-
console.error(
54-
`Failed to send email to ${to}, ${subject}. Error ${error.name}: ${error.message}`
55-
);
56-
throw new EmailError(error);
56+
catch (error) {
57+
if (error instanceof Error) {
58+
console.error(
59+
`Failed to send email to ${to}, ${subject}. Error ${error.name}: ${error.message}`
60+
);
61+
throw new EmailError(error);
62+
} else {
63+
throw error;
64+
}
5765
}
5866
}
5967
}
Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
11
import { render } from "@react-email/render";
2+
import nodemailer from "nodemailer";
23
import { EmailError, MailMessage, MailTransport, PlainTextMailMessage } from "./index";
3-
import nodemailer from "nodemailer"
44

55
export type SmtpMailTransportOptions = {
6-
type: 'smtp',
6+
type: "smtp";
77
config: {
8-
host?: string,
9-
port?: number,
10-
secure?: boolean,
8+
host?: string;
9+
port?: number;
10+
secure?: boolean;
1111
auth?: {
12-
user?: string,
13-
pass?: string
14-
}
15-
}
16-
}
12+
user?: string;
13+
pass?: string;
14+
};
15+
};
16+
};
1717

1818
export class SmtpMailTransport implements MailTransport {
1919
#client: nodemailer.Transporter;
2020

2121
constructor(options: SmtpMailTransportOptions) {
22-
this.#client = nodemailer.createTransport(options.config)
22+
this.#client = nodemailer.createTransport(options.config);
2323
}
2424

25-
async send({to, from, replyTo, subject, react}: MailMessage): Promise<void> {
25+
async send({ to, from, replyTo, subject, react }: MailMessage): Promise<void> {
2626
try {
2727
await this.#client.sendMail({
2828
from: from,
@@ -31,16 +31,19 @@ export class SmtpMailTransport implements MailTransport {
3131
subject,
3232
html: render(react),
3333
});
34-
}
35-
catch (error: Error) {
36-
console.error(
37-
`Failed to send email to ${to}, ${subject}. Error ${error.name}: ${error.message}`
38-
);
39-
throw new EmailError(error);
34+
} catch (error) {
35+
if (error instanceof Error) {
36+
console.error(
37+
`Failed to send email to ${to}, ${subject}. Error ${error.name}: ${error.message}`
38+
);
39+
throw new EmailError(error);
40+
} else {
41+
throw error;
42+
}
4043
}
4144
}
4245

43-
async sendPlainText({to, from, replyTo, subject, text}: PlainTextMailMessage): Promise<void> {
46+
async sendPlainText({ to, from, replyTo, subject, text }: PlainTextMailMessage): Promise<void> {
4447
try {
4548
await this.#client.sendMail({
4649
from: from,
@@ -49,12 +52,15 @@ export class SmtpMailTransport implements MailTransport {
4952
subject,
5053
text: text,
5154
});
52-
}
53-
catch (error: Error) {
54-
console.error(
55-
`Failed to send email to ${to}, ${subject}. Error ${error.name}: ${error.message}`
56-
);
57-
throw new EmailError(error);
55+
} catch (error) {
56+
if (error instanceof Error) {
57+
console.error(
58+
`Failed to send email to ${to}, ${subject}. Error ${error.name}: ${error.message}`
59+
);
60+
throw new EmailError(error);
61+
} else {
62+
throw error;
63+
}
5864
}
5965
}
6066
}

0 commit comments

Comments
 (0)