#Update HTTP response status code for graphql errors

6 messages · Page 1 of 1 (latest)

proven hornet
#

I'd like to update my http status code for all my graphql requests to mirror the nested status code in the graphql error response.

For example, here's the response I'd get back if a request has an invalid auth token. I'm trying to make the http status code also a 401, not a 200. I'm using express and apollo as the drivers

{
  "errors": [
    {
      "message": "Unauthorized",
      "locations": [
        {
          "line": 1,
          "column": 7
        }
      ],
      "path": [
        "teeTimes"
      ],
      "extensions": {
        "code": "UNAUTHENTICATED",
        "originalError": {
          "message": "Unauthorized",
          "statusCode": 401
        }
      }
    }
  ],
  "data": null
}
sharp orchid
#

GraphQL always returns a 200

proven hornet
#

I've used graphql frameworks in other languages that let you customize the http status code. It's still extremely helpful for things like observability

#

I'm just curious to know if it's even possible with nestjs + graphql

sharp orchid
barren pecan