-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Description
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