router icon indicating copy to clipboard operation
router copied to clipboard

consistent error responses

Open deweyjose opened this issue 3 years ago • 2 comments

Describe the bug We see different error response shape depending on which router lifecycle event generates an error.

Sometimes the response body will have an errors[0].extensions.type, others will not.

To Reproduce

Invalid Variables:

request: query

query node($nodeId: ID!) {
  node(id: $nodeId) {
    ... on DemoBook {
      bookId
    }
  }
}
variables
{
	"nodeId": null
}

response: 400

{"errors":[{"message":"invalid type for variable: 'nodeId'","extensions":{"type":"ValidationInvalidTypeVariable","name":"nodeId"}}]}

we see traces and metrics for this event. we do not observe logs for this event. I actively tailed the K8s logs while running a small test in production and ran locally.

No Query String

request:

response: 400

{"data":null,"errors":[{"message":"Must provide query string."}]}

we do NOT see traces or metrics for this event. we do not observe logs for this event. I actively tailed the K8s logs while running a small test in production and ran locally.

Invalid Query String

request:

Book {\n      boo }\n}

response: 400

{"errors":[{"message":"parsing error: ERROR@0:4 \"expected definition\" Book"}]}

we see traces and metrics for this event. we do not observe logs for this event. I actively tailed the K8s logs while running a small test in production and ran locally.

Expected behavior

  • all error conditions covered in prometheus metrics.
  • all error response to have the same shape regarding extensions.type

Output If applicable, add output to help explain your problem.

Desktop (please complete the following information):

  • OS: [e.g. iOS]
  • Version [e.g. 22]

Additional context Add any other context about the problem here.

deweyjose avatar Nov 14 '22 21:11 deweyjose

Definitely agree there's some work to do here, and thanks for opening this!

Just to call out one thing I see here already, this shouldn't have data present since it happened before execution started, per spec:

{"data":null,"errors":[{"message":"Must provide query string."}]}

abernix avatar Nov 22 '22 13:11 abernix

I think we should be consistent with what apollo-server is doing about errors. https://www.apollographql.com/docs/apollo-server/data/errors/

bnjjj avatar Nov 28 '22 09:11 bnjjj