bedrock-validation
Advanced tools
Comparing version
# bedrock-validation ChangeLog | ||
## 5.2.1 - 2021-12-14 | ||
### Fixed | ||
- Fix `api.validate` to throw error if schema does not exist instead of | ||
returning middleware that raises the error. | ||
## 5.2.0 - 2021-07-23 | ||
@@ -4,0 +10,0 @@ |
@@ -121,13 +121,15 @@ /*! | ||
// schema does not exist | ||
if(notFound) { | ||
const err = new BedrockError( | ||
'Could not validate data; unknown schema name (' + notFound + ').', | ||
'UnknownSchema', {schema: notFound}); | ||
if(typeof callback === 'function') { | ||
return callback(err); | ||
} | ||
throw err; | ||
} | ||
// do immediate validation if data is present | ||
if(arguments.length > 1) { | ||
if(notFound) { | ||
const err = new BedrockError( | ||
'Could not validate data; unknown schema name (' + notFound + ').', | ||
'UnknownSchema', {schema: notFound}); | ||
if(typeof callback === 'function') { | ||
return callback(err); | ||
} | ||
throw err; | ||
} | ||
// use schema.body (assume 3 parameter is called w/string) | ||
@@ -137,11 +139,2 @@ return api.validateInstance(data, schemas.body, callback); | ||
// schema does not exist, return middle that raises error | ||
if(notFound) { | ||
return (req, res, next) => { | ||
next(new BedrockError( | ||
'Could not validate request; unknown schema name (' + notFound + ').', | ||
'UnknownSchema', {schema: notFound})); | ||
}; | ||
} | ||
// return validation middleware | ||
@@ -148,0 +141,0 @@ // both `query` and `body` may need to be validated |
{ | ||
"name": "bedrock-validation", | ||
"version": "5.2.0", | ||
"version": "5.2.1", | ||
"description": "Bedrock validation", | ||
@@ -5,0 +5,0 @@ "main": "./lib", |
@@ -71,2 +71,17 @@ /* | ||
}); | ||
it('should throw an UnknownSchema error when schema does not exist', | ||
function() { | ||
let result; | ||
let err; | ||
try { | ||
result = validation.validate('test'); | ||
} catch(e) { | ||
err = e; | ||
} | ||
should.exist(err); | ||
should.not.exist(result); | ||
err.name.should.equal('UnknownSchema'); | ||
}); | ||
}); | ||
@@ -73,0 +88,0 @@ |
62838
0.39%1455
0.41%