Remove redundant try/catch block

This commit is contained in:
Alex Holliday
2024-10-17 14:32:18 +08:00
parent 17ed90f76b
commit b69d495206
+6 -17
View File
@@ -44,7 +44,7 @@ class EmailService {
const templateContent = this.fs.readFileSync(templatePath, "utf8");
return this.compile(templateContent);
} catch (error) {
logger.error("Error loading Email templates", {
this.logger.error("Error loading Email templates", {
error,
service: this.SERVICE_NAME,
});
@@ -102,7 +102,7 @@ class EmailService {
const html = await this.mjml2html(mjml);
return html.html;
} catch (error) {
logger.error("Error building Email HTML", {
this.logger.error("Error building Email HTML", {
error,
service: SERVICE_NAME,
});
@@ -118,26 +118,15 @@ class EmailService {
});
return info;
} catch (error) {
logger.error("Error sending Email", {
this.logger.error("Error sending Email", {
error,
service: SERVICE_NAME,
});
}
};
try {
const info = await sendEmail(to, subject, await buildHtml(template, context));
return info.messageId;
} catch (error) {
error.service = SERVICE_NAME;
if (error.method === undefined) {
error.method = "buildAndSendEmail";
}
logger.error("Error building and sending Email", {
error,
service: SERVICE_NAME,
});
}
const html = await buildHtml(template, context);
const info = await sendEmail(to, subject, html);
return info?.messageId;
};
}
export default EmailService;