Giter Site home page Giter Site logo

hapi-raven's Introduction

hapi-raven Build Status

A Hapi plugin for sending exceptions to Sentry through Raven.

Setup

Options:

  • dsn: Your Sentry DSN (required)
  • client: An options object that will be passed directly to the client as its second argument (optional)
  • tags: An array of tags (strings) to apply to each captured error

Note that DSN configuration using process.env is not supported. If you wish to replicate the default environment variable behavior, you'll need to supply the value directly:

server.register({
  register: require('hapi-raven'),
  options: {
    dsn: process.env.SENTRY_DSN
  }
})

Usage

Once you register the plugin on a server, logging will happen automatically.

The plugin listens for 'request-error' events which are emitted any time reply is called with an error where err.isBoom === false. Note that the 'request-error' event is emitted for all thrown exceptions and passed errors that are not Boom errors. Transforming an error at an extension point (e.g. 'onPostHandler' or 'onPreResponse') into a Boom error will not prevent the event from being emitted on response.


Boom Non-500 Errors are Not Logged

server.route({
  method: 'GET',
  path: '/',
  handler: function (request, reply) {
    reply(Hapi.error.notFound())
  }
})

server.inject('/', function (response) {
  // nothing was logged
})

500 Errors are Logged

server.route({
  method: 'GET',
  path: '/throw',
  handler: function (request, reply) {
    throw new Error()
  }
})

server.inject('/throw', function (response) {
  // thrown error is logged to Sentry
})
server.route({
  method: 'GET',
  path: '/reply',
  handler: function (request, reply) {
    reply(new Error())
  }
})

server.inject('/throw', function (response) {
  // passed error is logged to Sentry
})

For convenience, hapi-raven exposes the node-raven client on your server as server.plugins.raven.client. If you want to capture errors other than those raised by 'request-error', you can use the client directly inside an 'onPreResponse' extension point.

Example: Capture all 404 errors

server.ext('onPreResponse', function (request, reply) {
  if (request.isBoom && request.response.statusCode === 404) {
    server.plugins.raven.client.captureError(request.response)
  }
})

hapi-raven's People

Contributors

bendrucker avatar fiws avatar greenkeeperio-bot avatar louisbl avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.