Skip to content

Instantly share code, notes, and snippets.

@georgecrawford
Last active July 15, 2016 11:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save georgecrawford/4880a22ac47b368301b9b2dee906cc13 to your computer and use it in GitHub Desktop.
Save georgecrawford/4880a22ac47b368301b9b2dee906cc13 to your computer and use it in GitHub Desktop.
description: "An error handler for Express/Raven which adds additional fields (tags, extra) set on the error object"
const raven = require('raven');
module.exports = client => (err, req, res, next) => {
const status = err.status || err.statusCode || err.status_code || 500;
// skip anything not marked as an internal server error
if(status < 500) return next(err);
const kwargs = raven.parsers.parseRequest(req);
// Merge any Sentry-like fields from the Error to the raven args
['tags', 'extra', 'user'].forEach(field => {
if(err[field] && (typeof err[field] === 'object')) {
kwargs[field] = Object.assign(err[field], kwargs[field]);
}
});
client.captureError(err, kwargs, (result) => {
res.sentry = client.getIdent(result);
next(err, req, res);
});
};
@apaleslimghost
Copy link

with the current description it's going to barf the next time you publish. it needs to be valid HJSON

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment