apicco-lib
Advanced tools
Comparing version 1.1.0 to 1.1.1
@@ -22,2 +22,3 @@ const path = require('path'); | ||
joiOptions = {}, | ||
errorCode = 422, | ||
verbose = false | ||
@@ -67,2 +68,3 @@ } = {}) { | ||
joi, | ||
errorCode, | ||
schema: validate, | ||
@@ -69,0 +71,0 @@ options: joiOptions |
{ | ||
"name": "apicco-lib", | ||
"version": "1.1.0", | ||
"version": "1.1.1", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -22,3 +22,5 @@ const Boom = require('boom'); | ||
function validate({ schema = {}, options = {}, joi } = {}) { | ||
function validate({ | ||
schema = {}, options = {}, errorCode = 422, joi | ||
} = {}) { | ||
return (ctx, next) => { | ||
@@ -31,5 +33,12 @@ const opts = merge({}, { abortEarly: false }, options); | ||
if (!isEmpty(error)) { | ||
throw Boom.badData('', { | ||
details: buildErrorDetails(error.details) | ||
}); | ||
switch (errorCode) { | ||
case 400: | ||
throw Boom.badRequest('', { | ||
details: buildErrorDetails(error.details) | ||
}); | ||
default: | ||
throw Boom.badData('', { | ||
details: buildErrorDetails(error.details) | ||
}); | ||
} | ||
} | ||
@@ -36,0 +45,0 @@ } |
@@ -40,2 +40,19 @@ /* eslint-env jest */ | ||
}); | ||
test('throws a 400 boom error when configured as such', async () => { | ||
const ctx = mockCtx(); | ||
const next = jest.fn(); | ||
const schema = { foo: Joi.required() }; | ||
try { | ||
await validate({ | ||
schema, | ||
errorCode: 400, | ||
joi: Joi | ||
})(ctx, next); | ||
} catch (err) { | ||
expect(err.isBoom).toBeTruthy(); | ||
expect(err.output.statusCode).toBe(400); | ||
} | ||
}); | ||
}); | ||
@@ -42,0 +59,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
17496
279