{"success":true,"name":"pick-status-codes-and-error-bodies-that-tell-the-client-what","description":"Writing API responses and about to return errors or success codes","category":"ai-brimind","path":"ai-brimind/pick-status-codes-and-error-bodies-that-tell-the-client-what/SKILL.md","file":"SKILL.md","content":"---\nname: pick-status-codes-and-error-bodies-that-tell-the-client-what\ndescription: \"Writing API responses and about to return errors or success codes\"\n---\n\n# Pick Status Codes and Error Bodies That Tell the Client What To Do\n\n## When to use\nYou are implementing endpoint responses, and the status codes and error body shape are being chosen ad-hoc per case.\n\n## Example request\nEverything returns 200 with { success: false } inside → clients and monitoring can't tell failures apart; status codes are the standard signal. — 500 returned for a bad user input → on-call gets paged for a typo; 4xx means 'you sent it wrong', 5xx means 'we broke'. — Error body is a raw stack trace → leaks internals and helps nobody; a stable error envelope (code, message, field) is the contract. — 404 used for 'no permission' and 'doesn't exist' and 'deleted' → clients can't react correctly; each meaning has its own code.\n\n## Instructions\nAct as a response designer who believes every status code is an instruction to the client. When implementing responses: 1) Use the standard meanings — 2xx success (201 created, 202 accepted, 204 no content), 4xx caller's fault (400 invalid, 401 not logged in, 403 not allowed, 404 not found, 409 conflict), 5xx server's fault. Never wrap failures inside a 200. 2) Reuse the project's existing error envelope — one shape everywhere (e.g. code, message, offending field); if none exists, define one and apply it to every error, not just this endpoint. 3) For each failure path in the handler, ask: what should the CLIENT do when it gets this? Retry, fix input, log in, give up — the code and body must make that answer obvious. 4) Never leak internals: no stack traces, SQL, or file paths in responses; log those server-side with a correlation id instead. 5) If a case doesn't map cleanly to a code, check the convention or ask rather than inventing. Only finish once each path returns a confirmed, consistent signal, and explain how each choice guides the client's next move rather than just 'returning an error'.\n\n## Metadata\n- role: developer\n- level: tactical\n- places: vibeCoding\n- origin: ai.brimind.pro skill #889\n","linked_files":[],"origin":"ai.brimind.pro","owner_id":null,"source":"router"}