diff --git a/lib/hooks/http/get-configured-http-middleware-fns.js b/lib/hooks/http/get-configured-http-middleware-fns.js index 65762081f7..c8484b92ca 100644 --- a/lib/hooks/http/get-configured-http-middleware-fns.js +++ b/lib/hooks/http/get-configured-http-middleware-fns.js @@ -160,6 +160,15 @@ module.exports = function getBuiltInHttpMiddleware (expressRouterMiddleware, sai var opts = {}; var fn; + opts.onBodyParserError = function (err, req, res, next) { + var bodyParserFailureErrorMsg = 'Unable to parse HTTP body- error occurred :: ' + util.inspect((err&&err.stack)?err.stack:err, false, null); + sails.log.error(bodyParserFailureErrorMsg); + if (IS_NODE_ENV_PRODUCTION && sails.config.keepResponseErrors !== true) { + return res.status(400).send(); + } + return res.status(400).send(bodyParserFailureErrorMsg); + }; + // Handle original bodyParser config: //////////////////////////////////////////////////////// // If a body parser was configured, use it @@ -178,25 +187,6 @@ module.exports = function getBuiltInHttpMiddleware (expressRouterMiddleware, sai })(), - // Should be installed immediately after the bodyParser- prevents bubbling to - // the default error handler which will attempt to use body parameters, which may - // cause unexpected issues. - // - // (included here so it still protects against this edge case if bodyParser - // is overridden in userland. Should probably be phased out at some point, - // since it could be accomplished more elegantly- but for now it's practical.) - // - // * TODO: fold this into Skipper itself, perhaps as an "errorHandlerFn" option. - handleBodyParserError: function handleBodyParserError(err, req, res, next) { - var bodyParserFailureErrorMsg = 'Unable to parse HTTP body- error occurred :: ' + util.inspect((err&&err.stack)?err.stack:err, false, null); - sails.log.error(bodyParserFailureErrorMsg); - if (IS_NODE_ENV_PRODUCTION && sails.config.keepResponseErrors !== true) { - return res.status(400).send(); - } - return res.status(400).send(bodyParserFailureErrorMsg); - }, - - // Allow simulation of PUT and DELETE HTTP methods for user agents // which don't support it natively (looks for a `_method` param) methodOverride: (function() { diff --git a/lib/hooks/http/index.js b/lib/hooks/http/index.js index 3d51eaebf6..536f57b158 100644 --- a/lib/hooks/http/index.js +++ b/lib/hooks/http/index.js @@ -53,7 +53,6 @@ module.exports = function(sails) { 'cookieParser', 'session', 'bodyParser', - 'handleBodyParserError', 'compress', 'methodOverride', 'poweredBy', diff --git a/package.json b/package.json index 06b6b64321..ce0de3a115 100644 --- a/package.json +++ b/package.json @@ -66,7 +66,7 @@ "semver": "4.3.6", "serve-favicon": "2.3.0", "serve-static": "1.10.2", - "skipper": "~0.6.0", + "skipper": "~0.7.0", "sort-route-addresses": "^0.0.1", "uid-safe": "1.1.0", "vary": "1.1.0",