Merge pull request #430 from PradnyaBaviskar/issue709
Return 400 when client provides an incorrect value
This commit is contained in:
commit
2e2e01cc5c
|
@ -13,7 +13,9 @@ function List(items, itemType, parent) {
|
|||
try {
|
||||
items = JSON.parse(items);
|
||||
} catch (e) {
|
||||
throw new Error(util.format('could not create List from JSON string: %j', items));
|
||||
var err = new Error(util.format('could not create List from JSON string: %j', items));
|
||||
err.statusCode = 400;
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -22,7 +24,9 @@ function List(items, itemType, parent) {
|
|||
|
||||
items = items || [];
|
||||
if (!Array.isArray(items)) {
|
||||
throw new Error(util.format('Items must be an array: %j', items));
|
||||
var err = new Error(util.format('Items must be an array: %j', items));
|
||||
err.statusCode = 400;
|
||||
throw err;
|
||||
}
|
||||
|
||||
if(!itemType) {
|
||||
|
|
|
@ -23,6 +23,32 @@ describe('datatypes', function () {
|
|||
});
|
||||
});
|
||||
|
||||
it('should return 400 when property of type array is set to string value',
|
||||
function (done) {
|
||||
var myModel = db.define('myModel', {
|
||||
list: { type: ['object'] }
|
||||
});
|
||||
|
||||
(function(){
|
||||
myModel.create({ list: 'This string will crash the server' });
|
||||
}).should.throw({ statusCode: 400 });
|
||||
|
||||
done();
|
||||
});
|
||||
|
||||
it('should return 400 when property of type array is set to object value',
|
||||
function (done) {
|
||||
var myModel = db.define('myModel', {
|
||||
list: { type: ['object'] }
|
||||
});
|
||||
|
||||
(function(){
|
||||
myModel.create({ list: { key: 'This string will crash the server' } });
|
||||
}).should.throw({ statusCode: 400 });
|
||||
|
||||
done();
|
||||
});
|
||||
|
||||
it('should keep types when get read data from db', function (done) {
|
||||
var d = new Date, id;
|
||||
|
||||
|
|
Loading…
Reference in New Issue