Fix the status codes for a payment webhook
Your task
An AI wrote a Flask webhook for payment events that wrapped everything in except Exception: pass and always returned 200. The provider took every 200 as "handled", so when fulfilment failed, nobody retried and paid orders were never shipped. The status code is the only signal the provider gets: 200 means done, 400 means never send it again, and 500 means send it again later.
An assistant wrote webhook_response_status(outcomes). It is in the editor. It has a bug. Find it and fix it.
Input and output:
outcomes: what happened to each incoming event, in order, as a short code such asokordb_error.- Return the HTTP status to send for each event, in the same order, as integers.
Rules the tests check:
- Trim whitespace from both ends of each outcome first. Codes then match exactly, case included.
200forokandduplicate(a replay of an event already handled).400forbad_payloadandbad_signature. A retry would fail the same way.500forunknown_order,db_errorandfulfill_error. These can succeed on a later retry: anunknown_orderevent often arrives before the order it refers to is saved.500for any other code, including an empty one, so an unexpected failure is retried rather than marked done.
Examples
webhook_response_status(outcomes: list[str]) -> list[int]Example 1
Input
webhook_response_status(["ok", "db_error", "fulfill_error"])Output
[200, 500, 500]Example 2
Input
webhook_response_status(["bad_payload", "duplicate"])Output
[400, 200]Example 3
Input
webhook_response_status([])Output
[]