Skip to content

Instantly share code, notes, and snippets.

@philsch
Last active January 13, 2019 14:21
Show Gist options
  • Save philsch/adce29d2f7f59f6bcbba432c4a34a12f to your computer and use it in GitHub Desktop.
Save philsch/adce29d2f7f59f6bcbba432c4a34a12f to your computer and use it in GitHub Desktop.
Blogpost: Monitor your GraphQL Apollo Server in Google Cloud
// ...
const server = new ApolloServer({
typeDefs,
resolvers,
introspection: true,
playground: true,
formatError: (error) => {
/*
* Database connection error should appear in logs
* but not in Error Report as this is not considered a bug
*/
if (error.originalError instanceof DatabaseError) {
console.error('Database error occurred', error);
return error;
}
/*
* Some other Apollo error like wrong user input
* we don't need to log or report this,
* but still return the error back to the client
*/
if (error.originalError instanceof ApolloError) {
return error;
}
/*
* Something unexpected is wrong
*/
errorReporting.report(error.originalError.stack); // report to Google Error Report
console.error(error); // log the error
return {message: 'Internal Server Error'} // do not reveal error details to the client
}
});
const app = express();
server.applyMiddleware({app, path: '/graphql'});
// ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment