{"success":true,"name":"send-the-right-http-status-code-and-one-consistent-error-sha","description":"Writing or fixing backend API responses, especially error responses","category":"ai-brimind","path":"ai-brimind/send-the-right-http-status-code-and-one-consistent-error-sha/SKILL.md","file":"SKILL.md","content":"---\nname: send-the-right-http-status-code-and-one-consistent-error-sha\ndescription: \"Writing or fixing backend API responses, especially error responses\"\n---\n\n# Send the Right HTTP Status Code and One Consistent Error Shape\n\n## When to use\nProject has a backend API, and you are about to send a response (success or error) and might return 200 for everything or invent a new error format for this route.\n\n## Example request\nreturning 200 with { error: 'not found' } inside → the frontend thinks it succeeded and shows empty junk; a 404 lets normal error handling catch it. sending 500 for a user typing a bad email → logs fill with fake 'server crashes'; bad input is a 400, server bugs are 500 — the code tells who must fix it. each route inventing its own error JSON ({ msg }, { error }, { message }) → the frontend needs special code per route; one shared shape like { error: { code, message } } is the contract. returning the raw exception text to the client → it leaks internals and confuses users; log the details server-side, send a clean message out.\n\n## Instructions\nAct like an API responder who treats status codes as part of the contract, not decoration. Before sending any response, classify what happened: success (200/201), caller's fault — bad input, missing field, not found, no permission (400/404/401/403), or our fault — a real server bug (500). Pick the code that matches the class; never wrap an error inside a 200. Then check how the rest of this backend already formats errors and reuse that exact shape — same field names, same structure — instead of inventing a new one for this route; if no shared shape exists yet, propose one simple shape and use it. Log full technical details (stack, query, ids) on the server only; send the client a short, human message with no internals leaked. If you are unsure which class an error belongs to, trace where it comes from before choosing — do not default everything to 500 or 200. Only finish the endpoint once every exit path (success and each failure) has a deliberate status code and the shared error shape, and explain why this lets the frontend and the logs both instantly know who broke what.\n\n## Metadata\n- role: developer\n- level: tactical\n- places: vibeCoding\n- origin: ai.brimind.pro skill #516\n","linked_files":[],"origin":"ai.brimind.pro","owner_id":null,"source":"router"}