fixed email client not catching sending errors

logging errors to the database
This commit is contained in:
Miodec 2023-05-17 23:51:37 +02:00
parent d23d3ccf89
commit 5ff41ded22
2 changed files with 16 additions and 1 deletions

View file

@ -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");

View file

@ -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);
}