Errors
Errors and examples
Since our API is based on GraphQL, errors are specific and different than REST API status codes and errors.
There are several error types in GraphQL API. They are in relation to the operations that you performing.
The examples are listed below, but if you need more information, feel free to contact our Support, and we will provide you with help.
Error Examples
- When you make a request without a token or incorrect token you will receive a response with an
error
object. You will also receive an additional validation object including the error object.
Query companyTokens
request
query companyTokens($queryParams: PageRequestInput) {
companyTokens(pageRequestInput: $queryParams) {
data {
...SelectAllFields
__typename
}
totalCount
__typename
}
}
fragment SelectAllFields on CompanyToken {
id
name
isAllowed
permissions
created
expiration
lastUsed
modified
deleted
userId
user {
firstName
middleName
lastName
__typename
}
__typename
}
Query companyTokens
response - errors
{
"errors": [
{
"message": "You are not authorized to run this query.\nRequired claim 'permission' with any value of 'CompanyRead, 50' is not present.",
"locations": [
{
"line": 2,
"column": 3
}
],
"extensions": {
"code": "VALIDATION_ERROR",
"codes": [
"VALIDATION_ERROR"
],
"number": "authorization"
}
}
]
}
When you make an invalid request a response will be with an
errors
object.If you run a query with incorrect input parameters a response will be with an
error
object.
{
"data": null,
"errors": [
{
"message": "Cannot query field \"nonexistentField\" on type \"Mutations\".",
"status": 400,
"locations": [
{
"line": 4,
"column": 5
}
]
}
]
}
- The example below shows a response in the case the user's permissions and credentials are incorrect.
{
"errors": [
{
"message": "Cannot query field 'userLogin' on type 'Mutations'.",
"locations": [
{
"line": 2,
"column": 3
}
],
"extensions": {
"code": "FIELDS_ON_CORRECT_TYPE",
"codes": [
"FIELDS_ON_CORRECT_TYPE"
],
"number": "5.3.1"
}
}
]
}
- The example below shows what happens when incorrect
login parameters
are included in the query.
Query loginUser
example
mutation loginUser {
loginUser(username:"username", password:"xxxxx"){
authToken
}
}
Query loginUser
error response
{
"errors": [
{
"message": "Cannot query field 'loginUser' on type 'Mutations'. Did you mean 'logincompanyUser'?",
"locations": [
{
"line": 2,
"column": 3
}
],
"extensions": {
"code": "FIELDS_ON_CORRECT_TYPE",
"codes": [
"FIELDS_ON_CORRECT_TYPE"
],
"number": "5.3.1"
}
}
]
}
Although all error types contain a message field, the returned message is only meant for debugging. It is not suitable for display to your customers. Please use the code field and provide your own meaningful error messages.