mirror of
https://github.com/strapi/strapi.git
synced 2025-11-04 20:07:19 +00:00
better error handling in email (#6599)
Signed-off-by: Pierre Noël <petersg83@gmail.com>
This commit is contained in:
parent
7120bb2558
commit
9f277f67b5
@ -330,7 +330,7 @@ module.exports = ({ env }) => ({
|
|||||||
This plugin will allow configurations for each active environment.
|
This plugin will allow configurations for each active environment.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
npm install strapi-provider-upload-aws-s3@beta
|
npm install strapi-provider-upload-aws-s3
|
||||||
```
|
```
|
||||||
|
|
||||||
#### 4. Push your local changes to your project's GitHub repository.
|
#### 4. Push your local changes to your project's GitHub repository.
|
||||||
|
|||||||
@ -35,7 +35,7 @@ To install a new provider run:
|
|||||||
::: tab yarn
|
::: tab yarn
|
||||||
|
|
||||||
```
|
```
|
||||||
yarn add strapi-provider-email-sendgrid@beta --save
|
yarn add strapi-provider-email-sendgrid --save
|
||||||
```
|
```
|
||||||
|
|
||||||
:::
|
:::
|
||||||
@ -43,7 +43,7 @@ yarn add strapi-provider-email-sendgrid@beta --save
|
|||||||
::: tab npm
|
::: tab npm
|
||||||
|
|
||||||
```
|
```
|
||||||
npm install strapi-provider-email-sendgrid@beta --save
|
npm install strapi-provider-email-sendgrid --save
|
||||||
```
|
```
|
||||||
|
|
||||||
:::
|
:::
|
||||||
|
|||||||
@ -8,7 +8,15 @@
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
send: async ctx => {
|
send: async ctx => {
|
||||||
let options = ctx.request.body;
|
let options = ctx.request.body;
|
||||||
|
try {
|
||||||
await strapi.plugins.email.services.email.send(options);
|
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`
|
// Send 200 `ok`
|
||||||
ctx.send({});
|
ctx.send({});
|
||||||
|
|||||||
@ -26,7 +26,7 @@ module.exports = {
|
|||||||
|
|
||||||
client.sendEmail(removeUndefined(msg), function(err) {
|
client.sendEmail(removeUndefined(msg), function(err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
reject([{ messages: [{ id: 'Auth.form.error.email.invalid' }] }]);
|
reject(err);
|
||||||
} else {
|
} else {
|
||||||
resolve();
|
resolve();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -29,7 +29,7 @@ module.exports = {
|
|||||||
|
|
||||||
mailgun.messages().send(removeUndefined(msg), function(err) {
|
mailgun.messages().send(removeUndefined(msg), function(err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
reject([{ messages: [{ id: 'Auth.form.error.email.invalid' }] }]);
|
reject(err);
|
||||||
} else {
|
} else {
|
||||||
resolve();
|
resolve();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -26,7 +26,7 @@ module.exports = {
|
|||||||
|
|
||||||
sendgrid.send(removeUndefined(msg), function(err) {
|
sendgrid.send(removeUndefined(msg), function(err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
reject([{ messages: [{ id: 'Auth.form.error.email.invalid' }] }]);
|
reject(err);
|
||||||
} else {
|
} else {
|
||||||
resolve();
|
resolve();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -28,7 +28,7 @@ module.exports = {
|
|||||||
|
|
||||||
sendmail(removeUndefined(msg), err => {
|
sendmail(removeUndefined(msg), err => {
|
||||||
if (err) {
|
if (err) {
|
||||||
reject([{ messages: [{ id: 'Auth.form.error.email.invalid' }] }]);
|
reject(err);
|
||||||
} else {
|
} else {
|
||||||
resolve();
|
resolve();
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user