Skip to content

Send errors captured by graphql to sentry, bugsnag or similar

License

Notifications You must be signed in to change notification settings

eclass/graphql-notify-errors

This branch is 1 commit ahead of master.

Folders and files

NameName
Last commit message
Last commit date
May 7, 2018
May 7, 2018
May 7, 2018
May 7, 2018
May 7, 2018
May 7, 2018
May 7, 2018
May 7, 2018
Dec 2, 2022
Mar 26, 2022

Repository files navigation

graphql-notify-errors

npm version npm downloads devDependency Status

Send errors captured by graphql to sentry, bugsnag or similar

Installation

npm i graphql-notify-errors

Use

const { formatError, GraphQLError } = require('graphql')
const express = require('express')
const Raven = require('raven')
const NotifyErrors = require('graphql-notify-errors')

Raven.config(process.env.SENTRY_DSN).install()

const filter = err => !(err instanceof GraphQLError)
const options = {
  formatError,
  filter,
  notify: Raven.captureException
}
const notifyErrors = new NotifyErrors(options)
const app = express()
app.use('/graphql', graphqlExpress(req => {
    return {
      schema,
      context: { req },
      formatError: err => notifyErrors.formatError(err)
    }
  })
)

License

MIT