Skip to content

Commit

Permalink
(#159) - handle json body parser errors
Browse files Browse the repository at this point in the history
  • Loading branch information
marten-de-vries committed Jan 2, 2015
1 parent 47bd5b0 commit 887fa2b
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,20 @@
var rawBody = require('raw-body');

//shared middleware
exports.jsonParser = require('body-parser').json({limit: '1mb'});
var jsonParser = require('body-parser').json({limit: '1mb'})

exports.jsonParser = function (req, res, next) {
jsonParser(req, res, function (err) {
if (err) {
return exports.sendError(res, {
error: "bad_request",
reason: "invalid_json"
}, 400);
}
next();
});
};

exports.urlencodedParser = require('body-parser').urlencoded({extended: false});

//helpers
Expand Down

0 comments on commit 887fa2b

Please sign in to comment.