-
Notifications
You must be signed in to change notification settings - Fork 399
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GraphQL error handling #1053
Comments
This is a show-stopper - every single thrown HTTP exception results in INTERNAL_SERVER_ERROR, making GraphQL unusable in nest. Any updates? |
I found a workaround. https://www.apollographql.com/docs/apollo-server/data/errors/ You can import these erros like:
Then it will work as intended. |
+1 The //edit: Ok, it's possible to install |
+1 |
You can pass a formatError: (error: GraphQLError) => {
const graphQLFormattedError: GraphQLFormattedError = {
message: error.extensions?.exception?.response?.message || error.message,
};
return graphQLFormattedError;
} I found the answer here: https://stackoverflow.com/a/64129469/5959721 |
So what is the possible fix for this currently? Is that we use apollo server errors instead of the BadRequestException of nestjs? How do we handle with class validator errors as well? Is there a way to check the difference between both possible error types? |
@leograde Thanks for the tip. I added my own custom formatter that looks like this
Is there any benefit behind returning the |
This comment has been minimized.
This comment has been minimized.
Another patch solution ...
Thanks to @prokopsimek @leograde |
This worked for me thanks @dayota |
Let's track this here #1292 |
Nest version: lastest.
Throwing errors with Nest HttpException does not play well with GraphQL.
throw new UnauthorizedException()
will generate the following:While
throw new AuthenticationError("AuthenticationError")
fromimport { AuthenticationError } from "apollo-server-express"
will generate the proper friendly error:When using the GraphQL the error responses should be in second format.
https://www.apollographql.com/docs/apollo-server/data/errors/
The text was updated successfully, but these errors were encountered: