1.0.1 • Published 8 years ago

field-validation-error v1.0.1

Weekly downloads
5
License
WTFPL
Repository
github
Last release
8 years ago

FieldValidationError

When you've messed something up

Dependency Status devDependency Status

An exception for use in certain situations (e.g. to signal that some fields didn't pass validation). Created because of a need for a cross-package standard exception.

Getting started

Install the package with this command:

npm install field-validation-error --save

Usage

// Import ES6-style
import FieldValidationError from 'field-validation-error';

// Or CommonJS-style
const FieldValidationError = require('field-validation-error');

// Then just use like this:
throw new FieldValidationError({ name: 'Name is missing' });

// You can get access to the fields on a thrown exception using the `fields` property:
try {
  ...
} catch (err) {
  if (err instanceof FieldValidationError) {
    console.error('Invalid fields:', err.fields);
  }
}

Contributing

In lieu of a formal style guide, take care to maintain the existing coding style.

License

Copyright (c) 2016 Rafał Ruciński. Licensed under the WTFPL license.