From a526443bffd7efa66e3f503715d6126f5b5bc670 Mon Sep 17 00:00:00 2001 From: neymar <0208mjkim@gmail.com> Date: Tue, 8 Oct 2024 20:11:30 +0900 Subject: [PATCH] Add: notifyEmailFailureToReportChannel --- src/modules/email.js | 17 ++++++++++++----- src/modules/slackNotification.js | 20 ++++++++++++++++++++ 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/src/modules/email.js b/src/modules/email.js index 2ccfce8c..1822922d 100644 --- a/src/modules/email.js +++ b/src/modules/email.js @@ -1,6 +1,7 @@ const nodemailer = require("nodemailer"); const logger = require("./logger"); const { nodeEnv } = require("../../loadenv"); +const { notifyEmailFailureToReportChannel } = require("../modules/slackNotification"); /** * production 환경에서 메일을 전송하기 위해 사용되는 agent입니다. @@ -32,7 +33,7 @@ class NodemailerTransport { return true; } catch (err) { logger.error(`Failed to send email: ${err}`); - return false; + return err; } } } @@ -103,7 +104,7 @@ class MockNodemailerTransport { return true; } catch (err) { logger.error(`Failed to send email: ${err}`); - return false; + return err; } } } @@ -129,15 +130,21 @@ const sendReportEmail = async (reportedEmail, report, html) => { "etc-reason": "기타 사유", }; - return transporter.sendMail({ + const mailOptions = { from: "taxi@sparcs.org", to: reportedEmail, subject: `[SPARCS TAXI] 신고가 접수되었습니다 (사유: ${ reportTypeMap[report.type] })`, html, - }); -}; + } + + const result = await transporter.sendMail(mailOptions); + + if (result instanceof Error) { + notifyEmailFailureToReportChannel(mailOptions, report, result); + } +} module.exports = { sendReportEmail, diff --git a/src/modules/slackNotification.js b/src/modules/slackNotification.js index 544e8a31..bebc25e9 100644 --- a/src/modules/slackNotification.js +++ b/src/modules/slackNotification.js @@ -48,8 +48,28 @@ const notifyRoomCreationAbuseToReportChannel = ( ); }; +const notifyEmailFailureToReportChannel = ( + mailOption, + report, + error +) => { + sendTextToReportChannel( + `${mailOption.to}님께 보내려는 신고 메일이 실패했습니다. + + 신고자 ID: ${report.creatorId} + 신고 ID: ${report.reportedId} + 방 ID: ${report.roomId ?? ""} + 사유: ${report.type} + 기타: ${report.etcDetail} + + 문제 원인: ${error.message} + ` + ) +} + module.exports = { sendTextToReportChannel, notifyReportToReportChannel, notifyRoomCreationAbuseToReportChannel, + notifyEmailFailureToReportChannel };