Last active
January 27, 2016 01:04
-
-
Save andrewjmead/ded8e77f245dc5dec5e8 to your computer and use it in GitHub Desktop.
Example body-parse error handling
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
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