Your API returns 200 for everything and puts the failure inside the JSON body. It works fine in your own frontend, because you wrote the check. Then a customer builds against it, their retry middleware sees a 200 and moves on, and their error alerting stays quiet while the failures pile up. You find out from a support ticket.
The status code is part of your API's contract. Clients, retry loops, load balancers, and uptime monitors all read the number first and the body second, if they read it at all. These seven codes are the ones worth getting right, with what each one actually means and when to send it.
When you are unsure which code fits, one question settles most cases: what happened when the request ran?
1. 200 OK with an error body
The everything-is-200 habit. The handler catches every exception and returns 200 with {"success": false, "error": "card_declined"}. Now every client has to parse the body to learn the request failed, while retry middleware, status-based dashboards, and health checks all record success. RFC 9110 is plain about this: 200 means the request succeeded. If the charge failed, that is a 4xx. My advice: pick the real code and keep the body for detail. The body explains; the code decides.
2. 401 when you mean 403
401 Unauthorized means the request carries no valid credentials: nobody is logged in, or the token is missing, expired, or invalid. A 401 response should carry a WWW-Authenticate header so the client knows how to authenticate. 403 Forbidden is different: the credentials are fine and the server still refuses, because this user may not touch that resource. Re-authenticating never fixes a 403. If your API returns 403 for an expired token, a well-behaved client skips its token-refresh flow and strands the user on an error screen.
3. 404 when you mean 410
404 Not Found says nothing about history. The resource is not here, and it may never have existed. 410 Gone says it existed and it is not coming back. Use 410 for things you deleted on purpose: a removed short link, an account that was closed, an old endpoint you shut down for good. Crawlers and clients treat 410 as a signal to drop the reference permanently, while they will keep retrying a 404 in case it comes back.
4. 400 when you mean 422
400 Bad Request is for a request the server cannot parse: malformed JSON, broken syntax, bad framing. 422 Unprocessable Content is for a request that parsed fine but fails your rules: the end date comes before the start date, the email field holds a phone number. If your validation layer returns 400 for a semantically wrong value, the client cannot tell "you sent garbage" apart from "you sent the wrong value." Parsers produce 400. Validators produce 422.
5. 200 for creates when 201 exists
A POST that creates a resource deserves 201 Created, with a Location header pointing at the new thing. Returning 200 with the object in the body loses information: 200 says "you got a response," 201 says "something new now exists, and here is where." The same logic covers deletes. When a DELETE succeeds and there is nothing to send back, 204 No Content says exactly that, and no client has to wonder whether the empty body was an accident.
6. 429 without Retry-After
A rate limit response tells the client to slow down. Without a Retry-After header, the client guesses how long to wait, and those guesses are either useless or aggressive enough to get blocked harder. RFC 9110 says a 429 should include Retry-After, either as a number of seconds or a date. One header turns your rate limiter from a wall into a queue.
7. 500 when you mean 503
500 Internal Server Error means your code hit a condition it did not expect: an unhandled exception, a bug. If the service is down on purpose, for maintenance or because you are shedding load, 503 Service Unavailable is the honest code, and like 429 it should carry Retry-After. Clients and CDNs treat 503 as safe to retry. A 500 during planned downtime sends your on-call chasing a crash that never happened.
The short version
- 200 means it worked. Failures get a real 4xx or 5xx, not an error field.
- 401 is "who are you," 403 is "I know who you are, and no."
- 404 is "not here," 410 is "gone for good."
- 400 is "I cannot parse this," 422 is "I parsed it and it is wrong."
- Creates return 201 with a
Location. Deletes with nothing to say return 204. - 429 and 503 both carry
Retry-After. - 500 is for crashes, not for planned downtime.
If you do one thing after reading this, grep your handlers for the ones that always return 200 and start there. That is usually where the quiet failures live.
Sources: RFC 9110, HTTP Semantics and the MDN HTTP response status codes reference.
I write more about building and shipping on Substack.
Cover photo by imgix on Unsplash, free to use.

Top comments (0)