GraphQL operations return errors in a standardized format:

  • Each response may include an errors array
  • Each error contains:
    • message: Human-readable error description
    • extensions: Additional metadata and error codes

Always check the error object in the response rather than HTTP status codes. Examples below demonstrate common error scenarios.

Example 1: GraphQL Validation Error

{
  "errors": [
    {
      "message": "Cannot query field \"UID\" on type \"Device\". Did you mean \"UUID\" or \"_id\"?",
      "locations": [
        {
          "line": 5,
          "column": 5
        }
      ],
      "extensions": {
        "code": "GRAPHQL_VALIDATION_FAILED"
      }
    }
  ]
}

Example 2: Device Already Paired Error

{
  "errors": [
    {
      "message": "This device is already paired",
      "extensions": {
        "code": "406",
        "response": {
          "statusCode": 406,
          "message": "This device is already paired",
          "error": "Not Acceptable"
        }
      }
    }
  ],
  "data": null
}

Explanation

  • GraphQL Validation Error: This example shows an error when a field is queried incorrectly. It includes a message, location, and an error code.
  • Device Already Paired Error: This example shows a business logic error with a specific status code and message.