8000 Fixed validation error detection. · johnrees/arangodb@43063dc · GitHub
[go: up one dir, main page]

Skip to content

Commit 43063dc

Browse files
committed
Fixed validation error detection.
1 parent dd8d965 commit 43063dc

File tree

2 files changed

+6
-12
lines changed

2 files changed

+6
-12
lines changed

js/server/modules/org/arangodb/foxx/request_context.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ var SwaggerDocs = require("org/arangodb/foxx/swaggerDocs").Docs,
3535
internal = require("org/arangodb/foxx/internals"),
3636
toJSONSchema = require("org/arangodb/foxx/schema").toJSONSchema,
3737
is = require("org/arangodb/is"),
38+
BadRequest = require("http-errors").BadRequest,
3839
UnauthorizedError = require("org/arangodb/foxx/authentication").UnauthorizedError;
3940

4041
function createBodyParamExtractor(rootElement, paramName, allowInvalid) {
@@ -100,7 +101,7 @@ function validateOrThrow(raw, schema, allowInvalid) {
100101
}
101102
var result = joi.validate(raw, schema);
102103
if (result.error && !allowInvalid) {
103-
throw result.error;
104+
throw new BadRequest(result.error.message);
104105
}
105106
return result.value;
106107
}

js/server/tests/shell-foxx.js

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -964,9 +964,7 @@ function DocumentationAndConstraintsSpec () {
964964
paramName = 'flurb',
965965
description = stub(),
966966
requestBody = 'banana',
967-
schema = joi.array().items({x: joi.number().integer().required()}),
968-
called = false,
969-
thrown = false;
967+
schema = joi.array().items({x: joi.number().integer().required()});
970968
971969
allow(req)
972970
.toReceive("body")
@@ -979,15 +977,10 @@ function DocumentationAndConstraintsSpec () {
979977
type: schema
980978
});
981979

982-
try {
983-
var callback = transformRoute(routes[0].action);
984-
callback(req, res);
985-
} catch(e) {
986-
thrown = true;
987-
}
980+
var callback = transformRoute(routes[0].action);
981+
callback(req, res);
988982

989-
assertTrue(thrown);
990-
assertFalse(called);
983+
assertEqual(res.responseCode, 400);
991984
},
992985

993986
testSetParamForUndocumentedBodyParam: function () {

0 commit comments

Comments
 (0)
0