From 6b546034f4ef0790df0dc4ac54c6b42a412bc5d1 Mon Sep 17 00:00:00 2001 From: Reginald Bondoc Date: Sat, 10 Dec 2022 22:05:19 +0100 Subject: [PATCH] Use Sentry instead of console logs --- backend/src/helpers/nodemailer.ts | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/backend/src/helpers/nodemailer.ts b/backend/src/helpers/nodemailer.ts index 93633e4fa..1c92af93f 100644 --- a/backend/src/helpers/nodemailer.ts +++ b/backend/src/helpers/nodemailer.ts @@ -1,4 +1,3 @@ -/* eslint-disable no-console */ import fs from 'fs'; import path from 'path'; import handlebars from 'handlebars'; @@ -11,6 +10,7 @@ import { SMTP_PASSWORD } from '../config'; import SMTPConnection from 'nodemailer/lib/smtp-connection'; +import * as Sentry from '@sentry/node'; const mailOpts: SMTPConnection.Options = { host: SMTP_HOST, @@ -26,12 +26,16 @@ if (SMTP_USERNAME && SMTP_PASSWORD) { const transporter = nodemailer.createTransport(mailOpts); transporter .verify() - .then(() => console.log('SMTP - Successfully connected')) - .catch((err) => - console.log( + .then(() => { + Sentry.setUser(null); + Sentry.captureMessage('SMTP - Successfully connected'); + }) + .catch((err) => { + Sentry.setUser(null); + Sentry.captureException( `SMTP - Failed to connect to ${SMTP_HOST}:${SMTP_PORT} \n\t${err}` - ) - ); + ); + }); /** * @param {Object} obj @@ -66,7 +70,8 @@ const sendMail = async ({ html: htmlToSend }); } catch (err) { - console.error(err); + Sentry.setUser(null); + Sentry.captureException(err); } };