Skip to content

Commit

Permalink
Improve raven error monitoring
Browse files Browse the repository at this point in the history
  • Loading branch information
jpnelson committed Jun 9, 2018
1 parent 6111c32 commit 13da754
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ const Raven = require("raven");
let ravenUrl = process.env.RAVEN_URL;
if (ravenUrl) {
Raven.config(process.env.RAVEN_URL).install();

// The request handler must be the first middleware on the app
app.use(Raven.requestHandler());
app.use(Raven.errorHandler());
}

const html = fs.readFileSync("./index.html", "utf8");
Expand Down Expand Up @@ -59,4 +63,22 @@ app.get("/", (req, res) => {
}
});

if (ravenUrl) {
// 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(8080, () => console.log("App listening on port 8080"));

0 comments on commit 13da754

Please sign in to comment.