8 Examples of Common API Errors and Use Cases

Introduction

The following list contains common API error codes and their use cases.

404

404 – The requested resource could not be found

The server cannot find the requested resource on the server.

The resource you are looking for may have been deleted, its name changed, or is temporarily unavailable.

403

A client sends a request to the server and receives a response with HTTP status code 403. The body of this response contains information about what is wrong with the request, including the failure reason and a message. ‘mistake.

For instance:

“`ruby class SignUpController

400

The request could not be understood by the server due to incorrect syntax.

This is a server error, which means there is a problem with your application. The response has a 400 status code and a “Bad Request” message in its body, like this:

“`Bad request’`

500

Internal Server Error 500 is a standard error code used in many scenarios. This is a generic message indicating that the server encountered an error and does not provide additional information.

The response body of this status code usually contains more information about the type of error that occurred on the server. For instance:

“`{ “message”: “An unexpected condition was encountered”, “error”: { “code”: 500, “title”: “InternalServerError” } }”`

410

The server does not want to process the request due to a limitation. The server timed out, waiting for a response.

407

The query entity is too large. The body of the request message is too large.

408

The most common example is if you are trying to access a resource that requires authentication. For example, suppose your user is trying to access their account on the API, but they don’t have any credentials. The client will receive a 408 error and will need to prompt the user for their credentials before making another request.

429

429 is a permanent HTTP status code. This indicates that the server does not want to complete the request because it is too large. This can be due to several reasons, such as:

  • The request body is too large (e.g. POST data)
  • The request header is too large (for example, if you send a huge cookie value)

For instance, freecurrencyapi.com will return a 429 error status code when you reach your monthly quota limit.

These are common API error codes, along with their corresponding use cases.

API error codes are used by APIs to communicate errors to their users. There are many standardized API error codes, and they are often defined in the OpenAPI Specification (OAS) – a file that describes the structure of an API. For example, if you attempt to place a call that does not exist or is invalid, you may receive a 404 error code. This means that the requested resource cannot be found on this server. In addition to these everyday use cases for API errors, there are also less common ones that we’ll explore below.

Conclusion

The examples above are just a few of the most common error codes you will find in the wild. There are many more that we haven’t had time to cover here. Developers need to understand how they work and when they are appropriate to avoid bad experiences with their users.

About Shirley L. Kreger

Check Also

Three extraordinary examples of digital technology in action

Today, businesses apply many varieties of digital technologies to overhaul organizational processes. These technologies range …