fix(server): respond stripe webhook immediately

This commit is contained in:
forehalo 2023-10-24 11:46:29 +08:00
parent 2e4f6ef2ed
commit 7ecee01d20
No known key found for this signature in database

View File

@ -64,9 +64,14 @@ export class StripeWebhook {
`[${event.id}] Stripe Webhook {${event.type}} received.`
);
// handle duplicated events?
// see https://stripe.com/docs/webhooks#handle-duplicate-events
await this.event.emitAsync(event.type, event.data.object);
// Stripe requires responseing webhook immediately and handle event asynchronously.
setImmediate(() => {
// handle duplicated events?
// see https://stripe.com/docs/webhooks#handle-duplicate-events
this.event.emitAsync(event.type, event.data.object).catch(e => {
this.logger.error('Failed to handle Stripe Webhook event.', e);
});
});
} catch (err) {
this.logger.error('Stripe Webhook error', err);
throw new NotAcceptableException();