Pierre Noël 9f277f67b5
better error handling in email (#6599)
Signed-off-by: Pierre Noël <petersg83@gmail.com>
2020-06-09 12:11:25 +02:00

25 lines
510 B
JavaScript

'use strict';
/**
* Email.js controller
*
* @description: A set of functions called "actions" of the `email` plugin.
*/
module.exports = {
send: async ctx => {
let options = ctx.request.body;
try {
await strapi.plugins.email.services.email.send(options);
} catch (e) {
if (e.statusCode === 400) {
return ctx.badRequest(e.message);
} else {
throw new Error(`Couldn't send email: ${e.message}.`);
}
}
// Send 200 `ok`
ctx.send({});
},
};