Skip to content

Commit

Permalink
Merge pull request #3860 from balderdashy/fix-default-handlers
Browse files Browse the repository at this point in the history
[patch] Fix for issue introduced in [2037204]
  • Loading branch information
mikermcneil authored Oct 21, 2016
2 parents 0b204c5 + 132aaef commit 56efaf7
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions lib/router/bindDefaultHandlers.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/**
* Module dependencies
*/

var _ = require('lodash');

/**
* Default 500 and 404 handler.
* (defers to res.serverError() and res.notFound() whenever possible)
Expand Down Expand Up @@ -30,11 +36,16 @@ module.exports = function(sails) {
// a `status` property of 400 as if it were intentional. So we also check
// the error message. In Express 5, hopefully this can be improved a bit
// further.
var msgMatches = err.message.match(/^Failed to decode param \'([^']+)\'/);
if (err.status === 400 && msgMatches) {
sails.log.verbose('Bad request: Could not decode the requested URL ('+req.path+')');
// Note for future: The problematic URL section is: `msgMatches[1]`
return res.send(400, 'Bad request: Could not decode requested URL.');

if (_.isError(err)) {

var msgMatches = err.message.match(/^Failed to decode param \'([^']+)\'/);
if (err.status === 400 && msgMatches) {
sails.log.verbose('Bad request: Could not decode the requested URL ('+req.path+')');
// Note for future: The problematic URL section is: `msgMatches[1]`
return res.send(400, 'Bad request: Could not decode requested URL.');
}

}

// Next, try to use `res.negotiate()`, if it exists and is valid.
Expand Down

0 comments on commit 56efaf7

Please sign in to comment.