Error Handling
Gracefully handling errors is often an overlooked part of using an API. By doing so, you can be sure that your code will not fail unexpectedly and cause a cascade of unexpected behaviour throughout the rest of your application components. In this section, you may learn what types of errors are given by the API and how to handle them.
Unsuccessful API Operations
Any time a client request is not successful, the server will attempt to handle the error and generate a JSON-formatted response that would like like the following.
HTTP/1.1 404
Content-Type: application/json
{
"status": 404,
"error": "Route not found"
}
Both JSON key names are common across all errors displayed by the API, and represent the following.
status: The status code value, replicated from the actual HTTP response code.error: A brief explanation of the cause of the error.
An exception to this would imply something has gone terribly wrong or the API itself is down i.e. no response at all.
Last updated on