From b7e1ce020526d11fa445359cb866c7e452c2bc50 Mon Sep 17 00:00:00 2001 From: Sam Lade Date: Mon, 27 May 2019 14:12:14 +0100 Subject: [PATCH] Don't crash on email address lookup failure If for whatever reason an email job gets queued for a user with no email, an exception is thrown on the getEmailAddress() step. This exception was never handled and therefore the app crashed. Handle it and log instead.. --- jobs/mailer.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/jobs/mailer.js b/jobs/mailer.js index a3b21f565..cfa7f83f3 100644 --- a/jobs/mailer.js +++ b/jobs/mailer.js @@ -111,7 +111,12 @@ const processJob = transport => async ({ id, data }, done) => { const { message } = data; // Get the email address from the job data. - message.to = await getEmailAddress(data); + try { + message.to = await getEmailAddress(data); + } catch (err) { + logger.error({ err }, 'Failed to get user email address to send mail'); + return done(err); + } const log = logger.child({ jobID: id }); log.info('Starting to send mail');