async-deco
Advanced tools
Comparing version 7.4.0 to 7.5.0
{ | ||
"name": "async-deco", | ||
"version": "7.4.0", | ||
"version": "7.5.0", | ||
"description": "A collection of decorators for adding features to asynchronous functions (callback or promise based).", | ||
@@ -37,3 +37,3 @@ "main": "index.js", | ||
"memoize-cache-utils": "^0.0.2", | ||
"occamsrazor-match": "^2.2.1", | ||
"occamsrazor-match": "^3.0.0", | ||
"require-all": "^2.0.0", | ||
@@ -40,0 +40,0 @@ "setimmediate": "^1.0.4", |
@@ -261,2 +261,3 @@ async-deco | ||
``` | ||
The error returned contains a special "errors" property containing an array of all errors. | ||
@@ -263,0 +264,0 @@ Fallback |
var defaultLogger = require('../utils/default-logger'); | ||
var ValidatorError = require('../errors/validator-error'); | ||
var match = require('occamsrazor-match'); | ||
var and = require('occamsrazor-match/extra/and'); | ||
var validationErrors = require('occamsrazor-match/extra/validationErrors'); | ||
@@ -14,3 +16,4 @@ function validatorDecorator(wrapper, args) { | ||
var argsToValidate = Array.prototype.slice.call(arguments, 0, args.length - 1); | ||
if (validators(argsToValidate)) { | ||
var errors = validationErrors(); | ||
if (validators(argsToValidate, errors)) { | ||
func.apply(context, args); | ||
@@ -20,5 +23,6 @@ } else { | ||
validator: validators.name, | ||
args: args | ||
args: args, | ||
errors: errors() | ||
}); | ||
cb(new Error('Function called with wrong arguments: ' + validators.name)); | ||
cb(new ValidatorError('Function called with wrong arguments: ' + validators.name, errors())); | ||
} | ||
@@ -25,0 +29,0 @@ }; |
@@ -44,2 +44,4 @@ var assert = require('chai').assert; | ||
assert.equal(err.message, 'Function called with wrong arguments: array:[isNumber:2,or(isFalse isTrue)]'); | ||
assert.deepEqual(err.errors, [ | ||
{ path: '[0]', name: 'isNumber:2', value: 1 }]); | ||
done(); | ||
@@ -46,0 +48,0 @@ }); |
var match = require('occamsrazor-match'); | ||
var and = require('occamsrazor-match/extra/and'); | ||
var validationErrors = require('occamsrazor-match/extra/validationErrors'); | ||
var ValidatorError = require('../errors/validator-error'); | ||
@@ -12,6 +14,7 @@ function validatorDecorator() { | ||
var argsToValidate = Array.prototype.slice.call(arguments, 0, args.length); | ||
if (validators(argsToValidate)) { | ||
var errors = validationErrors(); | ||
if (validators(argsToValidate, errors)) { | ||
return func.apply(context, args); | ||
} else { | ||
throw new Error('Function called with wrong arguments: ' + validators.name); | ||
throw new ValidatorError('Function called with wrong arguments: ' + validators.name, errors()); | ||
} | ||
@@ -18,0 +21,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
146840
126
3901
734
+ Addedoccamsrazor-match@3.0.0(transitive)
- Removedoccamsrazor-match@2.2.1(transitive)
Updatedoccamsrazor-match@^3.0.0