Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Return an explicit error response from the Stripe webhook outer catch

Aperta Adatta ai principianti
#382 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@xlc ci sta già lavorando.

Dal 15/10/2026.

  • #388 di @xlc — aperta

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
72/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
nextjs, typescript

Direzione di ricerca

Inizia da src/app/api/stripe/webhook/route.ts, dal catch esterno intorno alle righe 49-57, dove NextResponse.json(...).headers.set('Allow', 'POST') viene usato come valore di ritorno. Nota che la chiamata awaited a prisma.user.update alle righe 35-43 è uno dei percorsi che porta a quel catch. Aggiungi test di route Jest in src/tests/unit/ che fanno await sull'handler POST esportato quando Prisma rifiuta e quando la lettura del body fallisce. È completato quando entrambi i casi restituiscono una Response con stato 500 e un body JSON generico, mentre i percorsi 400 e 200 restano invariati. Coordinati con #348, che copre lo stesso file di test della route.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

bug

Confirmed finding

src/app/api/stripe/webhook/route.ts:49–57 returns NextResponse.json(...).headers.set('Allow', 'POST'). Headers.set returns void, so the outer catch returns no response instead of the constructed JSON response. It also labels failures while processing an allowed POST as 405 Method Not Allowed.

The branch can be reached when request-body reading or prisma.user.update fails. The latter is awaited at lines 35–43. This is confirmed by source inspection; no live Stripe/database calls or tests were run.

Relationship and duplicate check

Related: #348 covers webhook signature validation and subscription-created tests. Its full body explicitly identifies this error-branch concern and requires any production-handler correction to have separate scope. This issue provides that separate fix scope; it does not replace or duplicate #348. No matching open fix issue was found.

Reproduction / verification setup

In an isolated route test, make event construction return a synthetic customer.subscription.created event, then make prisma.user.update reject. Await the exported POST handler and verify that it currently returns undefined rather than a Response. Also exercise rejection from request-body reading.

Scope / acceptance criteria

  • The outer catch explicitly returns a usable JSON Response for unexpected processing failures.
  • Unexpected processing failures receive an appropriate server-error status (500), not a misleading 405 or Allow header.
  • The response uses a generic error message and does not expose exception details or credentials.
  • Existing HTTP 400 signature/event-construction handling and HTTP 200 success acknowledgements remain unchanged.
  • Focused regression tests assert the response type, status, and body when Prisma rejects and when body reading fails.

Implementation surface and validation

Update src/app/api/stripe/webhook/route.ts and add isolated Jest route tests under src/__tests__/unit/, selecting a suitable environment for Next.js Response APIs. Mock Stripe, Prisma, and environment setup; do not require real credentials or external services. Coordinate the test file/setup with #348, but neither task requires a native blocking dependency. Run the focused tests, full Jest suite, and configured typecheck.

Out of scope: new Stripe event types, subscription lifecycle redesign, checkout changes, and unrelated API routes.

created by polka.codes

Lingua principale
TypeScript
Stelle
0
Fork
0
Merge medio
20m
PR unite (30g)
7

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di polka-codes/test

Tutte le issue di polka-codes/test

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.