[ ] Regression
[x] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.
Using Nestjs with the GraphQLModule as documentation describes, there are a problem with throwing HttpException. The error message that GraphQL returns, contains "[Object Object"] in the message field instead the HttpException message.
The GraphQL.js library is expecting an Error instance, but HttpException not inherit from Error. What is the main reason for HttpException is not extending from Error?
In addition to this any Exception Filter is not working.
Proper error handling and Exception Filters working with GraphQL.
Install @nestjs/graphql and configure it as documentation describes. In any resolver try to throw a HttpException (or a inherited custom one). GraphQL returns an error like this:
{
"data": {
"findOneUserById": null
},
"errors": [
{
"message": "[object Object]",
"locations": [
{
"line": 2,
"column": 3
}
],
"path": [
"findOneUserById"
]
}
]
}
Proper error handling working with GraphQL and documentation for how to deal with this.
- "@nestjs/common": "^4.5.9",
- "@nestjs/core": "^4.5.10",
- "@nestjs/graphql": "^2.0.0",
- "@nestjs/microservices": "^4.5.8",
- "@nestjs/testing": "^4.5.5",
- "@nestjs/websockets": "^4.5.8",
For Tooling issues:
- Node version: 9.4.0
- Platform: Linux
Others:
- Kubuntu
- WebStorm
- GraphiQL
- npm
I think the simplest "solution" would be to override the toString method to something like
class HttpException extends Error {
// ...
toString() {
return JSON.stringify(this);
}
}
this would result in {"mesage":"error...","code":200} instead of [object Object]
@kamilmysliwiec let me know if this seems like a good solution, I can submit a pr
Do you still encounter this issue with the latest release? (4.6.6)
I'm still encountering this issue with the current release! (5.0.0)
Any news how to fix that?
Any Solution?
same here 馃
also struggling with this (version 6.6.7)
Any Solution? @kamilmysliwiec
Still an issue on 6.5.3. Maybe there is some suggested workaround to make it work with e.g. apollo-link-error? The message field should contain the thrown error message used on the server and communicate that string to the client (instead of the [object Object] response).
bump
This is still an issue, especially when using the Federated GraphQL
Most helpful comment
I'm still encountering this issue with the current release! (5.0.0)
Any news how to fix that?