Skip to content
Advertisement

can I throw custom error in laravel-lighthouse

is the any way that throw an error by GraphQLErrorError with no additional data except message. the current return data is

{
  "errors": [
    {
      "message": "Some Errors",
      "extensions": {
        "reason": "",
        "category": "custom"
      },
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ],
      "path": [
        "to the path"
      ],
      "trace": [{},{},{},{}]
    }
  ],
  "data": {
    "testQuery": null
  }
}

it contains unnecessary data

but I want something like:

{
  "errors": [
    {
      "message": "Some Errors",
      "extensions": {
        "reason": "",
        "category": "custom"
      },
      
  ],
  "data": {
    "testQuery": null
  }
}

Advertisement

Answer

You can throw your own exceptions, that will allow you to do that. Check https://lighthouse-php.com/5/digging-deeper/error-handling.html#registering-error-handlers.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement