Is "404 Not Found" really a client error?
A time-traveler is passing by 2013 and she opens a browser bookmark to http://mars.gov/blog/**2056**/11/21/news.html
.
What HTTP status code does she get back from her response?
Well, it’s not going to be 200 OK
, because it wasn’t OK with the server. The server couldn’t find the article that the client requested, because it won’t be published for another 43 years.
“Couldn’t find the article” sounds like a 404 Not Found
status code. OK, very reasonable choice.
But, “The server couldn’t find the article” raises a bit of a doubt. A 404 is part of the 4xx-series status codes, which are all for client errors. Was this a client error, if it was the server’s fault for not finding the article? Shouldn’t she be getting 5xx Not Found
?
HTTP error status codes fall into two broad categories; 4xx (400 - 499) and 5xx (500 - 599). Understanding these categories is more important than understanding the specific error codes, because the categories communicate a very important piece of information. 4xx status codes represent a problem with the HTTP request, whereas 5xx status codes represent a problem with the HTTP server.
However, the line can be blurry between these two categories, if you just consider them the difference between “HTTP request” or “HTTP server”. If resources can be created in the future, and they can, then the exact same HTTP request that was 404 today could be a 200 tomorrow. So, is it really a problem with the request?
To address this confusion, I like to add an additional rule to clarify between 4xx and 5xx. When servicing an HTTP request, was it possible to give a 200 OK response? Let’s say it was a bug-free application server, or possibly even a human being manually processing HTTP requests. If it is possible, given perfect software or infinite resources or a brilliant mind, to process the request, but an error occurred, then it should be a 5xx code response. On the other hand, if no amount of perfection, resources, or brilliance would have been capable of processing that request, then it is a 4xx error.
Maybe our time-traveler should get back a 505 HTTP Version Not Supported
response, because the server could never have understood her attempt to use the HTTP/9.7 protocol. But other than that, she should get a good old 404 Not Found
; even with bug-free flawless server software, it was impossible to process her request. A 4xx error code suggests that the HTTP client needs to do something differently; like time-travel forward 43 years.