Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 22 additions & 26 deletions packages/polymath-offchain/src/routes/providers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
8 changes: 7 additions & 1 deletion packages/polymath-offchain/src/utils/emails.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down