Return an explicit error response from the Stripe webhook outer catch
I maintainer di solito rispondono entro 1 giorno
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 72/100
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
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
Allowheader. - 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
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di polka-codes/test
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
polka-codes/test#361 ·
I maintainer di solito rispondono entro 1 giorno
-
Expand homepage browser coverage beyond the document titleForse già presa @xlc l’ha presa 1 giorno fa. Apertaenhancement
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
polka-codes/test#349 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Validate helloAction input on the server before constructing a greetingForse già presa @xlc l’ha presa 1 giorno fa. Apertabug
Difficoltà 3/5 Mezza giornata Idoneità per principianti 72/100
polka-codes/test#381 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 1/100
polka-codes/test#366 ·
I maintainer di solito rispondono entro 1 giorno
-
enhancement
Difficoltà 3/5 1-2 giorni Idoneità per principianti 76/100
polka-codes/test#348 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di polka-codes/test
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
callstackincubator/simlock#639 ·
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 80/100
aws/agentcore-cli#2606 ·
I maintainer di solito rispondono entro 1 giorno
-
ai-driven-qa bug Cosmetic
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
I maintainer di solito rispondono entro 1 giorno
-
ai-driven-qa bug claude Minor
Difficoltà 2/5 1-3 ore Idoneità per principianti 64/100
linagora/twake-mail-admin#301 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
I maintainer di solito rispondono entro 1 giorno