Skip to content

Instantly share code, notes, and snippets.

@philsch
Last active February 10, 2019 15:45
Show Gist options
  • Save philsch/3e3e1362a7aa141ae24880bc28b4464b to your computer and use it in GitHub Desktop.
Save philsch/3e3e1362a7aa141ae24880bc28b4464b to your computer and use it in GitHub Desktop.
Blogpost: GraphQL Apollo Server errors and the request context
import {ApolloServer, SyntaxError, UserInputError, AuthenticationError, ForbiddenError} from 'apollo-server-express';
import {GraphQLErrorTrackingExtension} from 'graphql-error-tracking-extension';
import {ErrorReporting} from '@google-cloud/error-reporting';
const errorReporting = new ErrorReporting();
const server = new ApolloServer({
schema,
extensions: [() => new GraphQLErrorTrackingExtension({
maskHeaders: ['x-forwarded-for', 'authorization'],
revealErrorTypes: [SyntaxError, UserInputError, AuthenticationError, ForbiddenError],
onUnrevealedError: (err, originalError) => {
if (originalError) {
errorReporting.report(err.originalError.stack);
} else {
errorReporting.report(err.stack);
}
}
})],
context: ({req}) => ({
request: req
})
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment