From b69d495206a952fa9130fa373ca7aaaed8f1c9fd Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Thu, 17 Oct 2024 14:32:18 +0800 Subject: [PATCH] Remove redundant try/catch block --- Server/service/emailService.js | 23 ++++++----------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/Server/service/emailService.js b/Server/service/emailService.js index 40641ef42..519162ba0 100644 --- a/Server/service/emailService.js +++ b/Server/service/emailService.js @@ -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;