Status codes and errors

Every failed call tells you what went wrong twice, once in a three-digit code and once in a sentence. Learn to read both, decide what to do about each, and write one handler that does it for you.

When a call fails, beginners tend to change things at random until it works: re-copy the key, add a header, try a different parameter. Experienced developers read two things first, the status code and the error message, and usually know what to fix before they touch the code.

The status code is the three-digit number on the first line of every HTTP response, the 200 you saw with curl -i in lesson 1. It is designed to be read by a program, so your code can decide what to do without parsing English. The error field in the envelope is the same verdict written for a human. Between them, they answer the two questions that matter: what kind of problem is this, and what should change.

The five families

The first digit carries most of the meaning. You can look any code up with the HTTP Status Code Lookup API, which is a neat way to practise, since it is an API about the very thing that comes back from APIs:

Try it liveHTTP Status Code Lookup1 credit
GEThttps://api.apiverve.com/v1/httpstatuslookup
curl "https://api.apiverve.com/v1/httpstatuslookup?code=429" \
  -H "x-api-key: YOUR_API_KEY"
Sign in or create a free account to run this with your own key.

Read name and category, then try 401, 403 and 503.

{
  "status": "ok",
  "error": null,
  "data": {
    "code": 429,
    "name": "Too Many Requests",
    "description": "The user has sent too many requests in a given amount of time",
    "category": "Client Error",
    "is_error": true,
    "is_success": false,
    "is_redirect": false,
    "is_informational": false
  }
}
First digitFamilyWhose move is it?
1xxInformationalRarely seen directly; your HTTP client handles them
2xxSuccessNobody's. Read data
3xxRedirectYour HTTP client usually follows it automatically
4xxClient errorYours. Something about the request needs to change
5xxServer errorTheirs. The request may be fine; try again later

That last column is the most useful idea on this page. A 4xx means sending the same request again will get the same answer, so retrying is pointless until you change something. A 5xx means the server had a problem, and the identical request may well succeed in a few seconds. One exception to the rule lives in the 4xx range, and it gets its own section below.

Check yourself

A call returns a status in the 4xx range. In general, what should happen next?

Answer the check above to continue.

Run every example on your own key. Free plan, no card.

Scaling up?

Volume pricing, custom SLAs, and dedicated support for high-traffic teams.

Contact sales