mirror of https://gitee.com/bigwinds/arangodb
Fixed validation error detection.
This commit is contained in:
parent
136897d9c9
commit
f61671ded5
|
@ -35,6 +35,7 @@ var SwaggerDocs = require("org/arangodb/foxx/swaggerDocs").Docs,
|
|||
internal = require("org/arangodb/foxx/internals"),
|
||||
toJSONSchema = require("org/arangodb/foxx/schema").toJSONSchema,
|
||||
is = require("org/arangodb/is"),
|
||||
BadRequest = require("http-errors").BadRequest,
|
||||
UnauthorizedError = require("org/arangodb/foxx/authentication").UnauthorizedError;
|
||||
|
||||
function createBodyParamExtractor(rootElement, paramName, allowInvalid) {
|
||||
|
@ -100,7 +101,7 @@ function validateOrThrow(raw, schema, allowInvalid) {
|
|||
}
|
||||
var result = joi.validate(raw, schema);
|
||||
if (result.error && !allowInvalid) {
|
||||
throw result.error;
|
||||
throw new BadRequest(result.error.message);
|
||||
}
|
||||
return result.value;
|
||||
}
|
||||
|
|
|
@ -964,9 +964,7 @@ function DocumentationAndConstraintsSpec () {
|
|||
paramName = 'flurb',
|
||||
description = stub(),
|
||||
requestBody = 'banana',
|
||||
schema = joi.array().items({x: joi.number().integer().required()}),
|
||||
called = false,
|
||||
thrown = false;
|
||||
schema = joi.array().items({x: joi.number().integer().required()});
|
||||
|
||||
allow(req)
|
||||
.toReceive("body")
|
||||
|
@ -979,15 +977,10 @@ function DocumentationAndConstraintsSpec () {
|
|||
type: schema
|
||||
});
|
||||
|
||||
try {
|
||||
var callback = transformRoute(routes[0].action);
|
||||
callback(req, res);
|
||||
} catch(e) {
|
||||
thrown = true;
|
||||
}
|
||||
var callback = transformRoute(routes[0].action);
|
||||
callback(req, res);
|
||||
|
||||
assertTrue(thrown);
|
||||
assertFalse(called);
|
||||
assertEqual(res.responseCode, 400);
|
||||
},
|
||||
|
||||
testSetParamForUndocumentedBodyParam: function () {
|
||||
|
|
Loading…
Reference in New Issue