How to use common-errors - 10 common examples

To help you get started, we’ve selected a few common-errors examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mlrawlings / schema / lib / schema.js View on Github external
var errors = new ValidationError()
	  , schema = this

	definition = definition || schema.getActiveDefinition(data)
	options = options || {}

	if(!util.isExistent(data)) {
		if(!definition.required) return true
		if(util.isNull(data)) {
			throw new ValidationError('Required but got \'NULL\'', Schema.ErrorCodes.REQUIRED)
		}
		if(util.isNaN(data)) {
			throw new ValidationError('Required but got \'NaN\'', Schema.ErrorCodes.REQUIRED)
		}
		if(util.isUndefined(data)) {
			throw new ValidationError('Required but got \'undefined\'', Schema.ErrorCodes.REQUIRED)
		}
		if(util.isEmptyStr(data)) {
			throw new ValidationError('Required but got \'empty string\'', Schema.ErrorCodes.REQUIRED)
		}
		throw new ValidationError('Required failed test for existence', Schema.ErrorCodes.REQUIRED)
	}

	if(!util.typeMatch(data, definition.type)) {
		// build up the error text and throw at end
		// 'expected' 
		throw new ValidationError('expected '+definition.type.name)
	}

	if(util.isObject(data)) {
		Object.keys(data).forEach(function(key) {
			try {
github mlrawlings / schema / lib / schema.js View on Github external
if(util.isNaN(data)) {
			throw new ValidationError('Required but got \'NaN\'', Schema.ErrorCodes.REQUIRED)
		}
		if(util.isUndefined(data)) {
			throw new ValidationError('Required but got \'undefined\'', Schema.ErrorCodes.REQUIRED)
		}
		if(util.isEmptyStr(data)) {
			throw new ValidationError('Required but got \'empty string\'', Schema.ErrorCodes.REQUIRED)
		}
		throw new ValidationError('Required failed test for existence', Schema.ErrorCodes.REQUIRED)
	}

	if(!util.typeMatch(data, definition.type)) {
		// build up the error text and throw at end
		// 'expected' 
		throw new ValidationError('expected '+definition.type.name)
	}

	if(util.isObject(data)) {
		Object.keys(data).forEach(function(key) {
			try {
				schema.validate(data[key], options, definition.properties[key])
			} catch(e) {
				util.addNestedError(errors, e, key)
			}
		})
		definition.required && definition.required.forEach(function(key) {
			if(!util.isExistent(data[key]))
				errors.addError(new ValidationError('required'))
		})
	}
github mlrawlings / schema / lib / schema.js View on Github external
if(!util.isExistent(data)) {
		if(!definition.required) return true
		if(util.isNull(data)) {
			throw new ValidationError('Required but got \'NULL\'', Schema.ErrorCodes.REQUIRED)
		}
		if(util.isNaN(data)) {
			throw new ValidationError('Required but got \'NaN\'', Schema.ErrorCodes.REQUIRED)
		}
		if(util.isUndefined(data)) {
			throw new ValidationError('Required but got \'undefined\'', Schema.ErrorCodes.REQUIRED)
		}
		if(util.isEmptyStr(data)) {
			throw new ValidationError('Required but got \'empty string\'', Schema.ErrorCodes.REQUIRED)
		}
		throw new ValidationError('Required failed test for existence', Schema.ErrorCodes.REQUIRED)
	}

	if(!util.typeMatch(data, definition.type)) {
		// build up the error text and throw at end
		// 'expected' 
		throw new ValidationError('expected '+definition.type.name)
	}

	if(util.isObject(data)) {
		Object.keys(data).forEach(function(key) {
			try {
				schema.validate(data[key], options, definition.properties[key])
			} catch(e) {
				util.addNestedError(errors, e, key)
			}
		})
github mlrawlings / schema / lib / schema.js View on Github external
Schema.prototype.validate = function(data, options, definition) {
	var errors = new ValidationError()
	  , schema = this

	definition = definition || schema.getActiveDefinition(data)
	options = options || {}

	if(!util.isExistent(data)) {
		if(!definition.required) return true
		if(util.isNull(data)) {
			throw new ValidationError('Required but got \'NULL\'', Schema.ErrorCodes.REQUIRED)
		}
		if(util.isNaN(data)) {
			throw new ValidationError('Required but got \'NaN\'', Schema.ErrorCodes.REQUIRED)
		}
		if(util.isUndefined(data)) {
			throw new ValidationError('Required but got \'undefined\'', Schema.ErrorCodes.REQUIRED)
		}
		if(util.isEmptyStr(data)) {
			throw new ValidationError('Required but got \'empty string\'', Schema.ErrorCodes.REQUIRED)
		}
		throw new ValidationError('Required failed test for existence', Schema.ErrorCodes.REQUIRED)
	}

	if(!util.typeMatch(data, definition.type)) {
		// build up the error text and throw at end
		// 'expected' 
github mlrawlings / schema / lib / schema.js View on Github external
definition = definition || schema.getActiveDefinition(data)
	options = options || {}

	if(!util.isExistent(data)) {
		if(!definition.required) return true
		if(util.isNull(data)) {
			throw new ValidationError('Required but got \'NULL\'', Schema.ErrorCodes.REQUIRED)
		}
		if(util.isNaN(data)) {
			throw new ValidationError('Required but got \'NaN\'', Schema.ErrorCodes.REQUIRED)
		}
		if(util.isUndefined(data)) {
			throw new ValidationError('Required but got \'undefined\'', Schema.ErrorCodes.REQUIRED)
		}
		if(util.isEmptyStr(data)) {
			throw new ValidationError('Required but got \'empty string\'', Schema.ErrorCodes.REQUIRED)
		}
		throw new ValidationError('Required failed test for existence', Schema.ErrorCodes.REQUIRED)
	}

	if(!util.typeMatch(data, definition.type)) {
		// build up the error text and throw at end
		// 'expected' 
		throw new ValidationError('expected '+definition.type.name)
	}

	if(util.isObject(data)) {
		Object.keys(data).forEach(function(key) {
			try {
				schema.validate(data[key], options, definition.properties[key])
			} catch(e) {
				util.addNestedError(errors, e, key)
github mlrawlings / schema / lib / schema.js View on Github external
Schema.prototype.validate = function(data, options, definition) {
	var errors = new ValidationError()
	  , schema = this

	definition = definition || schema.getActiveDefinition(data)
	options = options || {}

	if(!util.isExistent(data)) {
		if(!definition.required) return true
		if(util.isNull(data)) {
			throw new ValidationError('Required but got \'NULL\'', Schema.ErrorCodes.REQUIRED)
		}
		if(util.isNaN(data)) {
			throw new ValidationError('Required but got \'NaN\'', Schema.ErrorCodes.REQUIRED)
		}
		if(util.isUndefined(data)) {
			throw new ValidationError('Required but got \'undefined\'', Schema.ErrorCodes.REQUIRED)
		}
		if(util.isEmptyStr(data)) {
			throw new ValidationError('Required but got \'empty string\'', Schema.ErrorCodes.REQUIRED)
		}
		throw new ValidationError('Required failed test for existence', Schema.ErrorCodes.REQUIRED)
	}

	if(!util.typeMatch(data, definition.type)) {
		// build up the error text and throw at end
		// 'expected' 
		throw new ValidationError('expected '+definition.type.name)
	}
github pandawing / node-run-yo / lib / mv-promised.js View on Github external
return new Promise(function (resolve, reject) {
    if (!value) {
      reject(new errors.TypeError('requires value[source], value[dest]'));
      return;
    }
    // FIXME
    if ([value['source'], value['dest']].some(function (key) {
      return key === null || key === '' || key === '.' || key === '/';
    })) {
      reject(new errors.ArgumentError('input is not allowed'));
      return;
    }

    mv(value['source'], value['dest'], { mkdirp: true }, function (err) {
      if (err) {
        reject(err);
        return;
      }
      resolve();
    });
  });
};
github pandawing / node-run-yo / lib / mv-promised.js View on Github external
return new Promise(function (resolve, reject) {
    if (!value) {
      reject(new errors.TypeError('requires value[source], value[dest]'));
      return;
    }
    // FIXME
    if ([value['source'], value['dest']].some(function (key) {
      return key === null || key === '' || key === '.' || key === '/';
    })) {
      reject(new errors.ArgumentError('input is not allowed'));
      return;
    }

    mv(value['source'], value['dest'], { mkdirp: true }, function (err) {
      if (err) {
        reject(err);
        return;
      }
      resolve();
github DaVarga / slingxdcc / server.js View on Github external
var app = module.exports = express();


        /**
         * Configuration
         */

            // all environments
        app.set('port', nconf.get('webserver:port'));
        app.set('views', __dirname + '/views');
        app.set('view engine', 'jade');

//        app.use(morgan('dev'));
        app.use(bodyParser.json());
        app.use(bodyParser.urlencoded({extended:false}));
        app.use(errors.middleware.crashProtector());
        app.use(methodOverride());
        app.use(express.static(path.join(__dirname, 'public')));
        app.use(log4js.connectLogger(httpLogger, { level: 'auto', format: ':remote-addr - :method :url HTTP/:http-version :status - :response-time ms',nolog: '\\.gif|\\.jpg$' }));
        
        /**
         * Routes
         */

        app.get('/', routes.index);
        app.get('/partials/:name', routes.partials);

        // JSON API

        app.get('/api/packet/', api.getNumPackets);

        app.get('/api/packet/get/:id', api.packet);
github getlackey / lackey-cms / lib / server / init / errors.js View on Github external
module.exports = (server) => {

    SCli.debug('lackey-cms/server/init/errors', 'Setting up');

    // If we got to this point there was no handler for this request
    server.use(module.exports.notFound);

    // Just in Case... Catch all!
    server.use(errors.middleware.crashProtector());
};
/* istanbul ignore next : external */