Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

async-deco

Package Overview
Dependencies
Maintainers
1
Versions
65
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

async-deco - npm Package Compare versions

Comparing version 7.4.0 to 7.5.0

errors/validator-error.js

4

package.json
{
"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 @@ };

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc