Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jpnelson/4ce5768eebe56ee44e4826db1a61864b to your computer and use it in GitHub Desktop.
Save jpnelson/4ce5768eebe56ee44e4826db1a61864b to your computer and use it in GitHub Desktop.
// An alternative fallback from https://docs.sentry.io/clients/node/integrations/express/#express
var app = require('express')();
var Raven = require('raven');
// Must configure Raven before doing anything else with it
Raven.config('__DSN__').install();
// The request handler must be the first middleware on the app
app.use(Raven.requestHandler());
app.get('/', function mainHandler(req, res) {
throw new Error('Broke!');
});
// The error handler must be before any other error middleware
app.use(Raven.errorHandler());
// Optional fallthrough error handler
app.use(function onError(err, req, res, next) {
// The error id is attached to `res.sentry` to be returned
// and optionally displayed to the user for support.
res.statusCode = 500;
res.send(
`Sorry! Something went wrong 💥. The maintainers have been notified, but if you'd like, you can <a href="https://github.com/jpnelson/fastjs/issues/new?title=Error%20in%20production&body=error_id=%22${
res.sentry
}%22">raise an issue on github</a> to give more details\n`
);
res.end();
});
app.listen(3000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment