Summary
I'm creating an issue here so you're aware, but I ultimately believe this is an issue with graphql-tools. When throwing a GrampsError, graphql-tools removes all properties except error.message and rethrows a new error. As a result, the formatError provided by the @gramps/errors package is useless.
Walkthrough
When a GrampsError is thrown, it is caught by graphql-tools stitching logic and rethrown:
https://github.com/apollographql/graphql-tools/blob/master/src/stitching/errors.ts#L84
const errorMessage = result.errors
.map((error: { message: string }) => error.message)
.join('\n');
throw locatedError(
new Error(errorMessage),
..,
..,
);
Later, the new error bubbles up to the formatError logic from @gramps/errors:
import { formatError } from '@gramps/errors'
app.use(graphqlExpress({ formatError })
However, the formatError function does not receive the expected GrampsErrors, rather, it receives a different error object transformed and rethrown by graphql-tools. It cannot log the targetEndpoint, statusCode, docsLink, and other fields on a GrampsError because the error has been caught and rethrown by graphql-tools.
I can write a short gist to reproduce it if you want.
Summary
I'm creating an issue here so you're aware, but I ultimately believe this is an issue with graphql-tools. When throwing a GrampsError, graphql-tools removes all properties except
error.messageand rethrows a new error. As a result, theformatErrorprovided by the@gramps/errorspackage is useless.Walkthrough
When a GrampsError is thrown, it is caught by graphql-tools stitching logic and rethrown:
https://github.com/apollographql/graphql-tools/blob/master/src/stitching/errors.ts#L84
Later, the new error bubbles up to the formatError logic from
@gramps/errors:However, the formatError function does not receive the expected GrampsErrors, rather, it receives a different error object transformed and rethrown by graphql-tools. It cannot log the targetEndpoint, statusCode, docsLink, and other fields on a GrampsError because the error has been caught and rethrown by graphql-tools.
I can write a short gist to reproduce it if you want.