1
0
Fork 0

Fixed validation error detection.

This commit is contained in:
Alan Plum 2015-06-04 00:58:38 +02:00
parent 136897d9c9
commit f61671ded5
2 changed files with 6 additions and 12 deletions

View File

@ -35,6 +35,7 @@ var SwaggerDocs = require("org/arangodb/foxx/swaggerDocs").Docs,
internal = require("org/arangodb/foxx/internals"), internal = require("org/arangodb/foxx/internals"),
toJSONSchema = require("org/arangodb/foxx/schema").toJSONSchema, toJSONSchema = require("org/arangodb/foxx/schema").toJSONSchema,
is = require("org/arangodb/is"), is = require("org/arangodb/is"),
BadRequest = require("http-errors").BadRequest,
UnauthorizedError = require("org/arangodb/foxx/authentication").UnauthorizedError; UnauthorizedError = require("org/arangodb/foxx/authentication").UnauthorizedError;
function createBodyParamExtractor(rootElement, paramName, allowInvalid) { function createBodyParamExtractor(rootElement, paramName, allowInvalid) {
@ -100,7 +101,7 @@ function validateOrThrow(raw, schema, allowInvalid) {
} }
var result = joi.validate(raw, schema); var result = joi.validate(raw, schema);
if (result.error && !allowInvalid) { if (result.error && !allowInvalid) {
throw result.error; throw new BadRequest(result.error.message);
} }
return result.value; return result.value;
} }

View File

@ -964,9 +964,7 @@ function DocumentationAndConstraintsSpec () {
paramName = 'flurb', paramName = 'flurb',
description = stub(), description = stub(),
requestBody = 'banana', requestBody = 'banana',
schema = joi.array().items({x: joi.number().integer().required()}), schema = joi.array().items({x: joi.number().integer().required()});
called = false,
thrown = false;
allow(req) allow(req)
.toReceive("body") .toReceive("body")
@ -979,15 +977,10 @@ function DocumentationAndConstraintsSpec () {
type: schema type: schema
}); });
try { var callback = transformRoute(routes[0].action);
var callback = transformRoute(routes[0].action); callback(req, res);
callback(req, res);
} catch(e) {
thrown = true;
}
assertTrue(thrown); assertEqual(res.responseCode, 400);
assertFalse(called);
}, },
testSetParamForUndocumentedBodyParam: function () { testSetParamForUndocumentedBodyParam: function () {