HTTP for HTML Authors, Part III - HTML with Style | 6
HTTP for HTML Authors, Part III
Error response codes
Together with the redirect response codes, these response codes give you a good repertoire with which to describe the outcome of form submission. But what if everything doesn't go according to plan with a request and there's some sort of error producing the requested resource?
HTTP defines several error codes for this case. There are two kinds of errors: Client errors and server errors. A client error indicates that the user agent did something wrong: issued a malformed HTTP request, tried to access an unauthorized resource or something similar. Server errors indicate that the server encountered an error when processing a request.
Much like 201 Created and 202 Accepted, these codes are meant to be associated with a document describing the specific nature of the error to the user. It's a good idea to supply contact details for support or links to main entry points into your site with these errors so as to help the user recover from the error.
These errors are usually created automatically by your Web server software, and the document is usually a very generic error message. It's a good idea to customize these error messages, both for making them more descriptive, and also so that they fit in with the design of the rest of your site.
Client error codes start with a 4; the most popular one by far is 404 Not Found, which we've already discussed; it should be, and often is, returned when the resource requested by the user agent does not exist in the server.
Other codes include 403 Forbidden, which indicates that although the requested resource might exist on the server, the user is not allowed to access it; perhaps because he has to log in with a username and password somewhere, or perhaps because he cannot access it unless he is on a local intranet.
405 Method Not Allowed indicates that you cannot use the specified HTTP request method to access this resource. This is useful for stopping enterprising individuals from using POST when they should be using GET or vice versa.
406 Not Acceptable indicates that the user has no document to return that is of a type acceptable to the user agent as specified in the various Accept- headers, which we discussed in Part II.
410 Gone is similar to a redirect, except that the server can't redirect you anywhere because the resource doesn't exist anywhere anymore. This is a very useful alternative to 404 Not Found in the case of removed documents, since it tells the user that yes, something used to be here, but it's not here anymore, so the user knows this isn't just a typo or a bad link.
From the server response codes, the most important one is 500 Internal Server Error. It's the HTTP equivalent of saying “Oops!” and raising your hands - it means that the server could not process the request for some unexpected reason. It is useful to allow the user to contact the administrator and submit a bug report for this error.
Another useful server error is 503 Service Unavailable. You can use this to inform users that the service they're asking for is temporarily unavailable, for instance if the system is undergoing maintenance or if it is overloaded.
URL: https://www.webreference.com/html/tutorial30/6.html
Produced by Stephanos Piperoglou
Created: March 15, 2001
Revised: March 16, 2001