Created
June 9, 2018 19:24
-
-
Save jpnelson/4ce5768eebe56ee44e4826db1a61864b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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