Skip to main content

Errors

A traditional REST API returns status via http codes. For example, 200 for OK or 404 for not found.

GraphQL APIs always return a 200 status code. Errors, if any, are described in the GraphQL response. See the GraphQL spec on errors for more info.

In addition, the Pera API adds (hopefully useful) information to the GQL response. For example, see the JSON response below:

{
"extensions":{
"success": false,
"code": "api.resource.not_found",
"status": 404,
},
"errors": [
{
"message": "Not Authenticated",
"code": "api.authentication.not_authenticated",
"status": 401,
"locations": [
{
"line": 2,
"column": 3
}
]
}
],
"data": {
"me": null
}
}

In the extensions field of a response we add the following fields:

  • success: a boolean value
  • code: an error code as a dotted string
  • status: a status code, similar to http status codes

For items in the error array, where possible, the code, status and a message associated with the error are set.