Errors

3. HTTP Status Codes and Errors

An HTTP request can fail because of a network error, because the browser blocked it, or because of problems encountered while the request is executing on the web server.

3.1 Network Errors

If a request cannot be sent, or no valid response is received, there is no HTTP status code. Instead, the browser's network stack reports an error code; in Chrome and Edge these have names like net::ERR_NAME_NOT_RESOLVED. Monitoring tools like HttpWatch display these error codes for situations such as:

  1. The host name could not be converted into an IP address, perhaps because an invalid host name was used or because no DNS lookup service is available.
  2. The browser could not connect to the web server. This may happen if the web server is not running, is listening on a different port, or a firewall is blocking the connection.
  3. The secure HTTPS connection could not be set up, for example because the server's certificate has expired or does not match the host name.
  4. The connection was closed or reset before a complete response was received.
  5. The browser blocked the request itself, for example an insecure HTTP request from an HTTPS page, a cross-origin request that the server has not allowed, or a request blocked by an extension such as an ad blocker.

3.2 Status Codes

HTTP status codes are returned by web servers to describe if and how a request was processed. The codes are grouped by the first digit:

1xx - Informational

Any code starting with '1' is an interim response that is sent before the final response. For example:

101

Switching Protocols is used when a connection changes to a different protocol, e.g. when an HTTP/1.1 connection is upgraded to a WebSocket connection.

103

Early Hints lets a server tell the browser which style sheets, scripts or other resources it should start loading, or which servers it should connect to, while the server is still generating the page.

2xx - Successful

These codes are used when a request has been successfully processed. For example:

200

OK is used when the requested resource is being returned in the body of the response message.

204

No Content indicates success when there is nothing to return, e.g. after an API call that deletes a record.

206

Partial Content is returned when the client used a range header to request just part of a resource, such as the next section of a video or the remainder of an interrupted download.

3xx - Redirection

Codes starting with a '3' indicate that the request was processed, but the browser should get the resource from another location, or from its cache. Some examples are:

301 / 308

The requested resource has moved permanently to the URL in the location response header. (See 7. Redirection)

302 / 303 / 307

The browser should temporarily get the resource from the URL supplied in the location response header. (See 7. Redirection)

304

The requested resource has not been modified and the browser should use the copy in its local cache instead. No content is returned with a 304 response (See 5. Caching for more detail)

4xx - Client Error

The server returns these codes when there is a problem with the client's request. Here are some examples:

400

Bad Request means the request was invalid, e.g. a form or API call supplied data in the wrong format.

401

Unauthorized means the client must authenticate to view the requested content. The www-authenticate response header specifies how, and the client supplies its credentials in the authorization request header. (See 9. Authentication for more detail)

403

Forbidden means the server understood the request but refuses to allow access, whoever the user is.

404

Not Found means the requested resource does not exist on the server.

429

Too Many Requests is returned when a client exceeds a rate limit. The retry-after header may indicate how long to wait before trying again.

5xx - Server Error

A status code starting with the digit 5 indicates that an error occurred on the server while processing the request. For example:

500

Internal Server Error means an error occurred on the server, perhaps because of an application error or configuration problem.

502 / 504

Bad Gateway and Gateway Timeout are returned by a proxy, load balancer or CDN when the web server behind it returned an invalid response or did not respond in time.

503

Service Unavailable means the service is temporarily unavailable, perhaps because of essential maintenance or overloading.

The full list of standard status codes is defined in RFC 9110.

Example 3

Question: Can you work out why the following images are not displayed correctly?

Image A: Image A

The host name used in the URL is missing a 'w' (i.e. ww rather than www) so the DNS lookup fails and the browser reports the error net::ERR_NAME_NOT_RESOLVED.

Image B: Image B

The URL for this image incorrectly uses port 81. Nothing accepts connections on that port, so the browser eventually gives up and reports net::ERR_CONNECTION_TIMED_OUT.

Image C: Image C

The web application aborted the request without sending a response. This site runs behind a front-end server that acts as a gateway, so the browser receives 502 Bad Gateway from the gateway. Without a gateway, the browser would report a network error such as net::ERR_EMPTY_RESPONSE or net::ERR_HTTP2_PROTOCOL_ERROR.

Image D: Image D

The request was processed by the server, but it returned 404 Not Found because the image does not exist at the specified location.

Image E: Image E

No access to this image is allowed. The server returned 403 Forbidden.

Image F: Image F

The server returned 501 Not Implemented, which means it does not support the functionality needed to handle the request.

Using HttpWatch with Example 3

To view the errors that occur when downloading the images:

  1. Open HttpWatch by pressing Ctrl+Shift+H, clicking the HttpWatch icon on the browser toolbar, or right-clicking the page and selecting HttpWatch
  2. Click on Record to start logging requests in HttpWatch
  3. Click on the Refresh this page button
  4. Optional: You can add a filter to capture only the images in Example 3 by adding a URL contains condition with the value "errors/images".
  5. The images that fail to download can be found by looking at the value in the Result column. If the value is too wide for the column, or you want an explanation of a network error, hold the mouse pointer over it to display a tooltip
  6. More detail on each image can be viewed by selecting the Overview tab

Ready to get started?

  • Free Basic Edition
  • No admin rights to install
  • HTTPS works out of the box