fix(billing): webhook reprocesses on handler failure (no lost events)

Self-audit finding: the idempotency row is written before processing,
so a handler exception/500 followed by Stripe's retry would be
suppressed as a duplicate and the event silently dropped. On the error
path, delete the dedupe row so the retry reprocesses. (Bad-signature/
config 400s and the non-unique insert-error 500 never wrote the row, so
those were already clean.)
This commit is contained in:
Moheeb Zara
2026-05-17 03:43:33 -07:00
parent ef9b0dc64f
commit ca34e5393a
+4
View File
@@ -181,6 +181,10 @@ export async function POST(
break
}
} catch (e) {
// The dedupe row was written BEFORE processing; if processing failed,
// remove it so Stripe's retry of this same event is reprocessed rather
// than silently short-circuited as a duplicate (no lost events).
await admin.from('stripe_webhook_events').delete().eq('event_id', event.id)
return NextResponse.json(
{ error: e instanceof Error ? e.message : 'handler error' },
{ status: 500 },