Errors
In this guide, we will talk about what happens when something goes wrong while you work with the API.
You can tell if your request was successful by checking the status code when receiving an API response and the presence of data
in the JSON response. If a response comes back unsuccessful, you can see the error type and message to figure out what has gone wrong and do initial debugging.
Status codes
Here is a list of the different categories of status codes returned by the HazelBase API. Use these to understand if a request was successful.
- Name
2xx
- Description
A 2xx status code indicates a successful response, however the response may still contain errors that require attention.
- Name
4xx
- Description
A 4xx status code indicates a client error.
- Name
5xx
- Description
A 5xx status code indicates a server error.
Errors
Errors follow the standard GraphQL error format, which is a JSON object with two keys: errors
and data
.
- Name
errors
- Description
The list of errors that occurred during the request. Each error includes a message, location, and extensions.
- Name
data
- Description
If any valid data was returned despite the errors, it will still be included in the response.
Error response
{
"errors": [
{
"message": "Cannot query field \"nonexistentField\" on type \"Query\".",
"locations": [
{
"line": 2,
"column": 3
}
],
"extensions": {
"code": "GRAPHQL_VALIDATION_FAILED",
"exception": {
"stacktrace": [
"GraphQLError: Cannot query field \"nonexistentField\" on type \"Query\".",
"...additional lines..."
]
}
}
}
],
"data": null
}