Responded with 409 when we have DB conflicts

refs https://github.com/TryGhost/Team/issues/789

We are still having issues with duplicate subscriptions being inserted,
despite running our code in transactions. For now we will catch these
errors and response ot Stripe with a 409 so that it'll retry later - and
it stops us from throwing 500's
This commit is contained in:
Fabien egg O'Carroll 2021-12-01 20:44:21 +02:00
parent 80a0e56d36
commit c99ebe589d

View File

@ -134,7 +134,17 @@ module.exports = class StripeWebhookService {
return;
}
await this[this.handlers[event.type]](event.data.object);
try {
await this[this.handlers[event.type]](event.data.object);
} catch (err) {
if (err.code !== 'ER_DUP_ENTRY' && err.code !== 'SQLITE_CONSTRAINT') {
throw err;
}
throw new errors.GhostError({
err,
statusCode: 409
});
}
}
async subscriptionEvent(subscription) {