-
Notifications
You must be signed in to change notification settings - Fork 2k
Design proper error names #1847
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
Comments
@IvanGoncharov is more exploration needed than simply replacing all |
@rogierschouten Sorry I didn't read carefully enough during initial triage. About the main topic of this issue on using a mixture of
I still think we need to distinguish between development errors, graphql-js own invariants, and errors triggered by clients. So I need to do some research on what other big libraries that extensively use callbacks are using e.g. React. Currently, I'm trying to finish two high priority issues for |
I agree, the most important thing is being able to distinguish between the different classes of errors. Thx! |
I am also encountering the same problem and would love to see the differentiation you are describing. |
@hassenc I'm not sure, but it should be something inside notes of previous meetings: |
Has there been any progress on this item lately? I have the same use-case as @rogierschouten - I'm formatting errors and trying to decide what is acceptable to expose to the client, and what should be masked. I use Apollo, and it seems that all errors from Apollo are wrapped by ApolloError, which makes it easy to filter - but the GraphQL errors seem to be all over the place. For now I'm doing a combination of checking if the error is a GraphQL error, and doing some text matching on the error message. Definitely not a great solution. Is there anything I can do to help out here? |
It would be great if graphql-js can at least add the error codes to the known errors like for input validations error with code BAD_USER_INPUT. onError(
new GraphQLError(
`Variable "$${varName}" of non-null type "${varTypeStr}" must not be null.`,
varDefNode,
undefined,
undefined,
undefined,
undefined,
{code:"BAD_USER_INPUT"}
), then it would make it easy for packages like Apollo to just check for code and return |
I think the library has improved since the issue was created, so that any remaining thrown errors that could be GraphQLErrors could be raised individually. In terms of an error class hierarchy, it probably should be based on a spec change, tracking until we have a spec PR in #3593 |
GraphQL-JS throws a variety of errors in normal everyday use e.g. GraphQLErrors, TypeErrors, and even regular JavaScript Error objects. All of these can occur because the client supplies garbage values to the server.
However, on the server side, I want to make a distinction between internal server errors (e.g. assertions, which should crash the server) and client errors (which should return a good client error message to the client).
To accomplish this, I tried to write a good formatError() function to give to express-graphql.
I cannot get this right, because e.g. graphql throws TypeErrors, which are indistinguishable from a server-side programming bug that causes a NodeJS TypeError.
So the proposal would be to ensure that graphql client errors are distinguishable from server errors, e.g. by giving all errors proper values for their 'name' and 'code' properties. This is also the direction in which NodeJS is going at the moment, see https://nodejs.org/api/errors.html#errors_error_code
The text was updated successfully, but these errors were encountered: