{"success":true,"name":"return-honest-http-status-codes-from-apis","description":"Building API endpoints and deciding what to return on success/failure.","category":"ai-brimind","path":"ai-brimind/return-honest-http-status-codes-from-apis/SKILL.md","file":"SKILL.md","content":"---\nname: return-honest-http-status-codes-from-apis\ndescription: \"Building API endpoints and deciding what to return on success/failure.\"\n---\n\n# Return Honest HTTP Status Codes From APIs\n\n## When to use\nYou are writing or fixing API responses, and errors are being returned as 200s with an error field, or every failure is a generic 500.\n\n## Example request\nValidation failure returned as 200 with {error:'bad email'} → frontend's error handling never triggers; monitoring sees all-green while users fail — lying status code. Everything wrong returns 500 → clients can't tell 'your fault, fix the request' (4xx) from 'our fault, retry later' (5xx) — lost signal. Missing resource returns 200 with empty body → the client renders a blank page instead of a not-found state — hidden 404.\n\n## Instructions\nAct like an API author who treats status codes as the contract's first word. For each endpoint outcome, choose the honest class: 2xx only when the operation truly succeeded (200 ok, 201 created, 204 no content); 4xx when the CLIENT must change something (400 invalid input, 401 not logged in, 403 logged in but not allowed, 404 doesn't exist, 409 conflict); 5xx when the SERVER failed and retrying might help. Rules: (1) never wrap failures in 200 — it blinds frontend error handling, retry logic, and monitoring simultaneously; (2) pair the code with a consistent error body (a message and optionally a field name) so clients can react programmatically; (3) distinguish 401 from 403 correctly — 'who are you?' versus 'you can't do that' — because clients handle them differently (redirect to login vs show denial). Walk each endpoint's failure cases and assign a code to every one deliberately. Only proceed once no failure path returns 2xx and a client could implement correct handling using status codes alone.\n\n## Metadata\n- role: developer\n- level: tactical\n- places: vibeCoding\n- origin: ai.brimind.pro skill #1093\n","linked_files":[],"origin":"ai.brimind.pro","owner_id":null,"source":"router"}