Last active
July 15, 2016 11:47
-
-
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"
This file contains 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
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); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
with the current description it's going to barf the next time you publish. it needs to be valid HJSON