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:
@@ -181,6 +181,10 @@ export async function POST(
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} 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(
|
return NextResponse.json(
|
||||||
{ error: e instanceof Error ? e.message : 'handler error' },
|
{ error: e instanceof Error ? e.message : 'handler error' },
|
||||||
{ status: 500 },
|
{ status: 500 },
|
||||||
|
|||||||
Reference in New Issue
Block a user