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:
Simon Backx 2022-12-14 10:48:46 +01:00 committed by GitHub
parent 3bd5dd66e0
commit 237d4d53d4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 5 deletions

View File

@ -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

View File

@ -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({