Errors
When interacting with the Emogg REST API, it's important to handle errors gracefully. The API uses conventional HTTP response codes to indicate the success or failure of requests. In case of an error, the API response will include a JSON object with detailed information to help diagnose and resolve the issue.
Response structure
The JSON error response contains the following fields:
| Field | Type | Description |
|---|---|---|
| error | bool | Set to true to indicate that the response is an error. |
| status | number | The HTTP status code associated with the error. |
| message | string | A human-readable string describing the cause of the error. |
Examples
{
"error": true,
"status": 404,
"message": "The requested resource was not found."
}
This example shows a 404 Not Found error response, where the message field provides a clear description of the issue.
Handling errors in your application
When your application encounters an error response from the API, it should:
- Check the status field to determine the type of error.
- Display the message to the user if appropriate, or log it for debugging purposes.
- Take corrective action based on the error type, such as ensure valid parameters are used for a 400 error or throttling requests for a 429 error.
Common HTTP status codes
Below is a table of the most common HTTP status codes returned by the Emogg REST API and their meanings:
| Code | Title | Description |
|---|---|---|
| 200 | OK | The request has succeeded. The client can read the result of the request in the body. |
| 201 | Created | The request has been fulfilled and resulted in a new resource being created. |
| 204 | No Content | The request has succeeded and there is no content to send for this request. |
| 400 | Bad Request | The server cannot or will not process the request due to something that is perceived to be a client error (e.g., malformed request syntax or insufficient funds). |
| 401 | Unauthorized | The request has not been proccessed because valid authentication credentials were not specified. |
| 404 | Not Found | The requested resource does not exist. |
| 429 | Too Many Requests | The user has sent too many requests in a given amount of time (see rate limiting). |
| 500 | Internal Server Error | Something went wrong on Emogg's end. (These are rare.) |
| 503 | Service Unavailable | Server is down for maintenance or is overloaded. |