I may be missing something, but as far as I can see, the only way to really customize the error returned from resolver functions is via the customFormatErrorFn option. The headers, status code, and graphqlErrors members of errors returned from resolver functions are ignored. The only member of the thrown error that is used is the result of toString.
On this line, error is set up, and from this point on the incoming rawError is not referenced.
This means that many of the if statements following are pointless since the condition will always return the same result.
for example:
...
response.statusCode = error.status; // always 500
const { headers } = error; // always comes from `httpError`
if (headers != null) {
for (const [key, value] of Object.entries(headers)) {
response.setHeader(key, String(value));
}
}
if (error.graphqlErrors == null) // always null
...
I may be missing something, but as far as I can see, the only way to really customize the error returned from resolver functions is via the
customFormatErrorFn
option. The headers, status code, andgraphqlErrors
members of errors returned from resolver functions are ignored. The only member of the thrown error that is used is the result oftoString
.https://github.com/graphql/express-graphql/blob/43ba6061388b9a1fc0119dc8e909c7a4391c70e6/src/index.ts#L371
On this line,
error
is set up, and from this point on the incomingrawError
is not referenced. This means that many of theif
statements following are pointless since the condition will always return the same result.for example: