From 4976488fd5a783f60c36947a1525772709435755 Mon Sep 17 00:00:00 2001 From: Remon Nashid Date: Tue, 30 Jul 2019 11:41:48 -0400 Subject: [PATCH] chore(issuer): catch all email errors instead of provider apps only --- .../polymath-offchain/src/routes/providers.js | 48 +++++++++---------- .../polymath-offchain/src/utils/emails.js | 8 +++- 2 files changed, 29 insertions(+), 27 deletions(-) diff --git a/packages/polymath-offchain/src/routes/providers.js b/packages/polymath-offchain/src/routes/providers.js index 4575fb1d7..03b0c8da3 100644 --- a/packages/polymath-offchain/src/routes/providers.js +++ b/packages/polymath-offchain/src/routes/providers.js @@ -227,38 +227,34 @@ export const applyHandler = async (ctx: Context) => { otherDetails, }; - try { - const { name: userName, email: userEmail } = user; - if ( - DEPLOYMENT_STAGE === 'production' && - NETWORKS[networkId].name === 'mainnet' - ) { - // Send emails to all selected providers - const providers = await Provider.find({ id: { $in: ids } }); - for (let provider of providers) { - const { name: providerName, email: providerEmail } = provider; - await sendProviderApplicationEmail( - providerEmail, - providerName, - userName, - userEmail, - application, - false - ); - } - } else { - // Send dummy email to the issuer instead of the provider + const { name: userName, email: userEmail } = user; + if ( + DEPLOYMENT_STAGE === 'production' && + NETWORKS[networkId].name === 'mainnet' + ) { + // Send emails to all selected providers + const providers = await Provider.find({ id: { $in: ids } }); + for (let provider of providers) { + const { name: providerName, email: providerEmail } = provider; await sendProviderApplicationEmail( - userEmail, - userName, + providerEmail, + providerName, userName, userEmail, application, - true + false ); } - } catch (error) { - console.error('Sendgrid error:', error, error.response.body.errors); + } else { + // Send dummy email to the issuer instead of the provider + await sendProviderApplicationEmail( + userEmail, + userName, + userName, + userEmail, + application, + true + ); } ctx.body = { diff --git a/packages/polymath-offchain/src/utils/emails.js b/packages/polymath-offchain/src/utils/emails.js index 7f1309062..8e8e4b0be 100644 --- a/packages/polymath-offchain/src/utils/emails.js +++ b/packages/polymath-offchain/src/utils/emails.js @@ -49,7 +49,13 @@ export const sendEmail = async ( html: body, }; if (SENDGRID_API_KEY) { - await sgMail.send(msg); + try { + await sgMail.send(msg); + } catch (error) { + logger.error('SendGrid error:', error.response.body.errors); + // Still throw the error in order to send it to Sentry. + throw error; + } } else { logger.warn('Not sending email since SENDGRID_API_KEY is not set.'); logger.warn(JSON.stringify(msg));