Blog

400 vs 409 vs 422: Three Ways an API Says "No"

September 17, 2026Xerat024 min read
Share
400 vs 409 vs 422: Three Ways an API Says "No"

A request fails validation, or collides with something that already exists, or is too malformed to even parse — and a lot of APIs return 400 for all three, because 400 is the one every developer remembers without looking it up. That's not wrong exactly (a client that only checks response.status >= 400 doesn't care), but it throws away information a more careful client — or a human reading the logs at 2am — could have used to tell three genuinely different problems apart.

400: the request itself is broken

400 Bad Request is for requests the server can't even make sense of at a structural level: malformed JSON, a required header missing entirely, a query string that fails to parse, a Content-Type that doesn't match the actual body. This is a transport-and-syntax problem, not a business-logic one — the test for whether something is a real 400 is whether fixing it means changing how the request is formatted, not what it contains.

409: the request is fine, reality disagrees

409 Conflict is for a request that's perfectly well-formed and valid on its own terms, but clashes with the server's current state: registering an email that's already taken, creating a resource with an ID that already exists, updating a record using a stale version number (optimistic concurrency control lives here). The request would have succeeded five minutes ago, or would succeed against different existing data — the problem isn't the request, it's the collision.

422: the request parses fine, the content doesn't

422 Unprocessable Content — RFC 9110 §15.5.21 actually renamed it from WebDAV's original "Unprocessable Entity" when 422 was folded into the core HTTP spec, though most frameworks and developers still say "Entity" out of habit — is for a request that's syntactically valid JSON, correctly formatted, nothing structurally wrong with it, but semantically invalid: age: -5, a required field missing from an otherwise well-formed body, an email field that isn't a valid email, a date that's in the past when the field requires a future one. The test: does fixing it mean changing what's in the request, with the format staying exactly the same? That's a 422.

The quick way to pick

Ask it in this order:

  1. Can the server even parse this? No → 400.
  2. Does the content, taken on its own, pass validation (types, required fields, formats, ranges)? No → 422.
  3. Is the content valid on its own, but conflicts with something that already exists on the server? Yes → 409.

The reason this order matters: a request can fail more than one of these checks at once (malformed JSON that, if it did parse, would also fail validation), and the earliest applicable one is the honest answer — you can't evaluate whether content is semantically valid if you couldn't parse it in the first place.

Why bothering with the distinction is worth it

A client's retry logic is the concrete place this pays for itself: a 409 is often worth retrying after re-fetching the current state (the classic "someone else edited this first" case, handled by reloading and reapplying the change) — it's a timing problem, not a permanent one. A 422 is never worth retrying unchanged, since retrying the identical invalid content produces the identical invalid result. A 400 usually means the client itself has a bug in how it builds requests, which is worth surfacing loudly rather than swallowing into a generic "something went wrong."

A client that treats all three as one undifferentiated "4xx, show an error" can't make any of those distinctions — and an API that returns 400 for a genuine data conflict is actively working against a client that's trying to.

Testing three failure shapes that usually only show up in production

Manually triggering a real 409 (an actual collision) is often more setup than a 422 (which just needs bad input) or a 400 (a malformed body an easy curl produces) — which is exactly why the collision case is the one most likely to be undertested. A conditional route that returns a specific status for a specific input lets you exercise a client's handling of all three codes independently, including the harder-to-manufacture 409 case, without needing to actually race two real requests against each other to prove it.

X

Xerat02

Building MockBase.