mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2025-02-27 08:13:28 +08:00
fixed email client not catching sending errors
logging errors to the database
This commit is contained in:
parent
d23d3ccf89
commit
5ff41ded22
2 changed files with 16 additions and 1 deletions
|
@ -102,7 +102,16 @@ export async function sendEmail<M extends EmailType>(
|
|||
html: template,
|
||||
};
|
||||
|
||||
const result = await transporter.sendMail(mailOptions);
|
||||
let result;
|
||||
try {
|
||||
result = await transporter.sendMail(mailOptions);
|
||||
} catch (e) {
|
||||
recordEmail(templateName, "fail");
|
||||
return {
|
||||
success: false,
|
||||
message: e.message,
|
||||
};
|
||||
}
|
||||
|
||||
recordEmail(templateName, result.accepted.length === 0 ? "fail" : "success");
|
||||
|
||||
|
|
|
@ -21,6 +21,12 @@ async function jobHandler(job: Job): Promise<void> {
|
|||
const result = await sendEmail(type, email, ctx);
|
||||
|
||||
if (!result.success) {
|
||||
Logger.logToDb("error_sending_email", {
|
||||
type,
|
||||
email,
|
||||
ctx: JSON.stringify(ctx),
|
||||
error: result.message,
|
||||
});
|
||||
throw new Error(result.message);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue