mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-25 03:44:29 +03:00
Added catch to unhandled promises rejections (#15994)
refs https://github.com/TryGhost/Team/issues/2370 Reduces amount of unhandled promise rejections
This commit is contained in:
parent
3bd5dd66e0
commit
237d4d53d4
@ -571,19 +571,25 @@ async function createEmailBatches({emailModel, memberRows, memberSegment, option
|
|||||||
return batchIds;
|
return batchIds;
|
||||||
}
|
}
|
||||||
|
|
||||||
const statusChangedHandler = (emailModel, options) => {
|
const statusChangedHandler = async (emailModel, options) => {
|
||||||
const emailRetried = emailModel.wasChanged()
|
const emailRetried = emailModel.wasChanged()
|
||||||
&& emailModel.get('status') === 'pending'
|
&& emailModel.get('status') === 'pending'
|
||||||
&& emailModel.previous('status') === 'failed';
|
&& emailModel.previous('status') === 'failed';
|
||||||
|
|
||||||
if (emailRetried) {
|
if (emailRetried) {
|
||||||
pendingEmailHandler(emailModel, options);
|
await pendingEmailHandler(emailModel, options);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
function listen() {
|
function listen() {
|
||||||
events.on('email.added', pendingEmailHandler);
|
events.on('email.added', (emailModel, options) => pendingEmailHandler(emailModel, options).catch((e) => {
|
||||||
events.on('email.edited', statusChangedHandler);
|
logging.error('Error in email.added event handler');
|
||||||
|
logging.error(e);
|
||||||
|
}));
|
||||||
|
events.on('email.edited', (emailModel, options) => statusChangedHandler(emailModel, options).catch((e) => {
|
||||||
|
logging.error('Error in email.edited event handler');
|
||||||
|
logging.error(e);
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Public API
|
// Public API
|
||||||
|
@ -22,7 +22,9 @@ async function configureApi() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const debouncedConfigureApi = _.debounce(() => {
|
const debouncedConfigureApi = _.debounce(() => {
|
||||||
configureApi();
|
configureApi().catch((err) => {
|
||||||
|
logging.error(err);
|
||||||
|
});
|
||||||
}, 600);
|
}, 600);
|
||||||
|
|
||||||
module.exports = new StripeService({
|
module.exports = new StripeService({
|
||||||
|
Loading…
Reference in New Issue
Block a user