Responses

Status code families

Use the first digit of an HTTP status code to quickly distinguish information, success, redirection, client errors, and server errors.

An HTTP status code is a three-digit number. The first digit tells you which family the response belongs to. Learn the five families and you can triage most problems in seconds.

  • 1xx: the exchange is still in progress (rare in everyday browsing).
  • 2xx: the request succeeded.
  • 3xx: redirection or cache revalidation.
  • 4xx: the client sent something the server refuses to fulfill as-is.
  • 5xx: the server failed while handling a request that looked valid.

The exact code narrows the story. 404 means the resource was not found. 401 means you need to authenticate. Both start with 4, so you look at the client and the request first, not server logs.

A 500 points the other way. The URL and method were plausible, but something broke inside the application or an upstream it depends on.

Do not treat every non-200 as failure. 201 Created is success after a POST. 204 No Content is success with no body. 301 Moved Permanently and 304 Not Modified are normal parts of healthy sites.

Probe a few families from the terminal:

curl -I https://flaviocopes.com/

Expect 200 in the first line.

curl -I https://flaviocopes.com/this-page-does-not-exist

Expect 404.

curl -I https://flaviocopes.com/books

Many sites redirect /books to another URL. You may see 301 or 308 with a Location header before curl follows the chain (add -L to follow automatically).

When I see an error in the browser, I note the family before I read the body. That habit saves time: client fixes for 4xx, server investigation for 5xx, cache or URL rules for 3xx.

Try this on your own project: hit a known-good URL, a deliberate bad path, and a redirect with curl -I and write down the first digit you see for each.

Lesson completed