Skip to content

Commit 81dd552

Browse files
committed
Pending retry
1 parent a741864 commit 81dd552

File tree

2 files changed

+19
-19
lines changed

2 files changed

+19
-19
lines changed

src/server/routes/mailchimp.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,6 @@ routes.get('/campaign-folders', (req, res) => new MailchimpService().getCampaign
2929

3030
routes.get('/campaigns', (req, res) => new MailchimpService().getCampaigns(req).then(res.send.bind(res)));
3131

32-
routes.post('/email', (req, res) => sendEmail(req, res));
32+
routes.post('/email', (req, res) => sendEmail(req, res).then(res.send.bind(res)));
3333

3434
export default routes;

src/server/services/sendGrid.js

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,23 @@ sgMail.setApiKey(config.SECRET.SENDGRID_API_KEY);
1414
* @param {Object} req the request
1515
* @param {Object} res the response
1616
*/
17-
export function sendEmail(req, res) {
18-
const msg = req.body;
19-
sgMail
20-
.send(msg)
21-
.then(result => res.json(result))
22-
.catch((error) => {
23-
logger.error(error);
24-
const { message, code, response } = error;
25-
res.status(code || 500);
26-
if (error.response) {
27-
const { headers, body } = response;
28-
res.json({
29-
message, headers, body,
30-
});
31-
}
32-
res.json({ message });
33-
});
34-
}
17+
export const sendEmail = async (req, res) => {
18+
try {
19+
const msg = req.body;
20+
const result = await sgMail.send(msg);
21+
return result;
22+
} catch (error) {
23+
logger.error(error);
24+
const { message, code, response } = error;
25+
res.status(code || 500);
26+
if (error.response) {
27+
const { headers, body } = response;
28+
return {
29+
message, headers, body,
30+
};
31+
}
32+
return { message };
33+
}
34+
};
3535

3636
export default undefined;

0 commit comments

Comments
 (0)