Skip to content

Instantly share code, notes, and snippets.

@andrewjmead
Last active January 27, 2016 01:04
Show Gist options
  • Save andrewjmead/ded8e77f245dc5dec5e8 to your computer and use it in GitHub Desktop.
Save andrewjmead/ded8e77f245dc5dec5e8 to your computer and use it in GitHub Desktop.
Example body-parse error handling
app.use(function(err, req, res, next) {
if (err instanceof SyntaxError) { // If invalid JSON
res.status(500).json({error: "INVALID_JSON"});
} else if (err) {
res.status(500).json({error: "SYSTEM_ERROR"});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment