🐛 Fixed email not showing as failed if error occurs when preparing email

no issue

- if an error occurred whilst creating email batch/recipient records the email status was never updated and was left in the 'pending' status
- adjusted the error handling to update the email status and record the error message if such a scenario occurs
This commit is contained in:
Kevin Ansfield 2020-10-02 12:40:49 +01:00
parent 7b789e1cd5
commit 0f30b9f6a0

View File

@ -226,14 +226,25 @@ async function sendEmailJob({emailModel, options}) {
startEmailSend = Date.now();
await bulkEmailService.processEmail({emailId: emailModel.get('id'), options});
debug(`sendEmailJob: sent email (${Date.now() - startEmailSend}ms)`);
} catch (err) {
} catch (error) {
if (startEmailSend) {
debug(`sendEmailJob: send email failed (${Date.now() - startEmailSend}ms)`);
}
logging.error(new errors.GhostError({
err: err,
let errorMessage = error.message;
if (errorMessage.length > 2000) {
errorMessage = errorMessage.substring(0, 2000);
}
await emailModel.save({
status: 'failed',
error: errorMessage
}, {patch: true});
throw new errors.GhostError({
err: error,
context: i18n.t('errors.services.mega.requestFailed.error')
}));
});
}
}