fix(server): respond stripe webhook immediately

This commit is contained in:
forehalo
2023-10-24 11:46:29 +08:00
parent 2e4f6ef2ed
commit 7ecee01d20

View File

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