mercurius
mercurius copied to clipboard
Gateway Service HTTP Errors
It looks like the Mercurius Gateway service expects "errors" to exist in the response, however, if I have a fastify plugin that throws an error before it ever hits GraphQL, then the gateway emits an error.
{
"errors": [
{
"message": "Cannot read property 'profile' of undefined",
"locations": [
{
"line": 2,
"column": 3
}
],
"path": [
"profile"
]
}
],
"data": null
}
It might be nice if Mercurius handled common HTTP errors (Unauthorized, Forbidden, etc) so that it just emits that error on those types of exceptions, or if each gateway service could configure it's response to format the error if it exists.
Sure thing! Would you like to send a Pull Request to address this issue? Remember to add unit tests.
@j I guess these http errors can be handled using a custom errorFormatter
(https://mercurius.dev/#/docs/api/options?id=error-formatter). Have you tried it?
@mcollina Do you think we should we should change the error implementation in mercurius to accommodate these http errors or leave it for now since the same can be achieved using the errorFormatter
?
I think some minimal change is needed, the described error is not a good DX. At a minimum, we should avoid that: make sure that we support the errors property to not be there.
I'm unsure we should add specific handling of http status codes.
@mcollina Do you mean we should remove the errors
property if the error is thrown by a fastify-plugin before the request reaches GraphQL?
Let me close this issue as I do not have much time to scope it.
@j can you please provide the code snippet that reproduces the issue? especially the part that triggers this particular error.