Recent chats
ASKGEEZ Q&A GUIDETechnology & devices

How should an API client interpret common 4xx status codes?

Quick answer

Treat a 4xx response as a clue that the server regards something about the request or its context as a client error, not as a complete explanation. For common cases: 400 suggests checking request details; 401, whether the request is authenticated; 403, whether access is allowed; 404, whether the resource can be found; 409, whether current server state conflicts with the request; and 422, whether the request’s meaning or values can be accepted. These are general HTTP meanings, not guarantees about an API’s error body or handling. [S1]

LET’S WORK THROUGH IT

The question, the details, the next step.

Question

I’m getting a 4xx response from an API. How should I use the status code to figure out what to check next?

Geez

Use the code to choose a diagnostic question, then compare that question with the request you actually sent and the API’s documentation. A 4xx status has a standardized general meaning, but an API may add its own behavior or error details; the code alone does not tell you exactly which field or condition caused the response. [S1]

Here’s a practical lookup:

  1. 400 — Bad Request: The server perceives the request as a client error. Ask: “Did I send the request in the format and shape this endpoint expects?” [S1]
  2. 401 — Unauthorized: In HTTP semantics, this means the request is unauthenticated. Ask: “Is the request being recognized as authenticated?” [S1]
  3. 403 — Forbidden: The request lacks access rights. Ask: “Is this operation allowed for the identity and context the API recognizes?” [S1]
  4. 404 — Not Found: The resource was not found. Ask: “Am I requesting the intended resource at the intended location?” An API may also use 404 rather than 403 to conceal that a resource exists. [S1]
  5. 409 — Conflict: The request conflicts with the server’s current state. Ask: “Has something about the resource’s state changed or made this operation conflict?” [S1]
  6. 422 — Unprocessable Content: The request is well-formed but cannot be followed because of semantic errors. Ask: “Are the supplied values meaningful and acceptable for this operation?” [S1]

These are starting points, not a diagnosis. The status code definitions do not establish what a particular API puts in its error body, or how that API handles each situation. [S1]

Follow-up question

How do I tell whether a 400 or 422 points me toward a different check?

Geez

Start by separating the request’s presentation from its meaning. For a 400, inspect the request against the endpoint’s documented format and expected shape: “Did I send what this endpoint says it accepts?” For a 422, the general HTTP meaning points to a request that is well-formed but cannot be followed because of semantic errors: “Do these values make sense for this operation?” [S1]

For example, suppose you’re testing a hypothetical endpoint that accepts a booking request. If your request does not match the documented structure, that is a reason to investigate the request format. If it matches the structure but contains a value the operation cannot make sense of, investigate the value’s meaning. This is an illustrative distinction, not a claim about how any particular booking API classifies errors. Check the API’s documentation and any response details before deciding what to change.

Follow-up question

What’s the useful distinction between 401, 403, and 404?

Geez

Use the status as a prompt, not as proof of a specific configuration problem. With 401, ask whether the request is recognized as authenticated; with 403, ask whether the recognized request has access rights for the action. Those are the general HTTP meanings. [S1] You do not need to guess at an implementation or attempt to get around an access restriction; check the API’s authorized-use documentation or ask its administrator what access is intended.

For 404, first check that you are requesting the intended resource and location. Keep in mind that a server may return 404 instead of 403 to conceal a resource’s existence, so a 404 does not always settle whether the resource exists. [S1] The status definitions do not establish why a particular API chose that response.

Follow-up question

Can you show me how to apply the lookup to a failed request without jumping to conclusions?

Geez

Assume a hypothetical client sends a request and receives 409. Record the code, then ask whether the operation conflicts with the server’s current state; that is the general meaning of 409. [S1] Compare the request and the state you expected with the API’s documented behavior. Don’t assume which state changed or whether repeating the request will help: the code definition does not identify the application-specific cause. [S1]

A compact triage note you can copy is:

Status: [code] Request/operation: [brief description; omit secrets] First diagnostic question: [question suggested by the code] What I checked: [request details and relevant API documentation] Still unknown: [what the code does not establish]

For a 409, the first diagnostic question could be: “What about the current server state might conflict with this operation?” For a 422, it could be: “Are the request’s values meaningful and acceptable for this operation?” These questions guide investigation; they do not promise a particular error body or remedy. [S1]

A practical checklist

  • Record the status code and the operation that returned it.

  • Use the matching lookup entry to form one diagnostic question.

  • Compare the request with the endpoint’s documented expectations.

  • Treat the API’s own documentation and response details as context, not as guaranteed by the status code.

  • Note what remains unknown before changing the request or asking the API administrator.

A few more useful answers

Does a 404 always mean the resource does not exist?

No. The general meaning is that the resource was not found, but a server may use 404 instead of 403 to conceal a resource’s existence. [S1]

Does a 422 tell me which value is wrong?

Not by itself. Its general meaning points to a well-formed request that cannot be followed because of semantic errors; the status definition does not establish what details a particular API provides. [S1]

Are these meanings guaranteed to describe every API’s exact behavior?

No. They are general HTTP semantics, and the reference notes that servers may use additional non-standard codes. Check the specific API’s documentation for its own behavior. [S1]

Sources

References used for this guide.

  1. [S1] MDN HTTP Reference: HTTP response status codes
    developer.mozilla.org · Checked

YOUR QUESTION. YOUR DETAILS.

Let’s work through your situation.

Get a tailored answer or help with your next task. Starts at $1, with a quote before you pay.

Ask your own question
← Back to Geez at Work