diff --git a/lib/dao.js b/lib/dao.js index 128aa921..f5a6886f 100644 --- a/lib/dao.js +++ b/lib/dao.js @@ -458,8 +458,9 @@ DataAccessObject._coerce = function (where) { return where; } + var err; if (typeof where !== 'object' || Array.isArray(where)) { - var err = new Error(util.format('The where clause %j is not an object', where)); + err = new Error(util.format('The where clause %j is not an object', where)); err.statusCode = 400; throw err; } @@ -473,6 +474,10 @@ DataAccessObject._coerce = function (where) { for (var i = 0; i < clauses.length; i++) { self._coerce(clauses[i]); } + } else { + err = new Error(util.format('The %p operator has invalid clauses %j', p, clauses)); + err.statusCode = 400; + throw err; } return where; } diff --git a/test/loopback-dl.test.js b/test/loopback-dl.test.js index 6b1d4049..d1d2b0a8 100644 --- a/test/loopback-dl.test.js +++ b/test/loopback-dl.test.js @@ -1086,7 +1086,7 @@ describe('DataAccessObject', function () { it('should throw if the where property is not an object', function () { try { // The where clause has to be an object - error = err;model._coerce('abc'); + model._coerce('abc'); } catch (err) { error = err; } @@ -1096,7 +1096,7 @@ describe('DataAccessObject', function () { it('should throw if the where property is an array', function () { try { // The where clause cannot be an array - error = err;model._coerce([ + model._coerce([ {vip: true} ]); } catch (err) { @@ -1108,7 +1108,7 @@ describe('DataAccessObject', function () { it('should throw if the and operator does not take an array', function () { try { // The and operator only takes an array of objects - error = err;model._coerce({and: {x: 1}}); + model._coerce({and: {x: 1}}); } catch (err) { error = err; } @@ -1118,7 +1118,7 @@ describe('DataAccessObject', function () { it('should throw if the or operator does not take an array', function () { try { // The or operator only takes an array of objects - error = err;model._coerce({or: {x: 1}}); + model._coerce({or: {x: 1}}); } catch (err) { error = err; } @@ -1128,7 +1128,7 @@ describe('DataAccessObject', function () { it('should throw if the or operator does not take an array of objects', function () { try { // The or operator only takes an array of objects - error = err;model._coerce({or: ['x']}); + model._coerce({or: ['x']}); } catch(err) { error = err; }