1.1.0 • Published 8 years ago

nu-error v1.1.0

Weekly downloads
6
License
MIT
Repository
github
Last release
8 years ago

nu-error

npm version Codecov Dependency Status

Easily create custom errors in Node.js

Install

npm install nu-error

Usage

nu-error exposes a single factory function.

CreateError(name: String) => errorFunction: Function, throws TypeError

Creates and returns an errorFunction bound to name.

errorFunction(message: String, extra: Object, constructorOpt: Function) => Error

Example

const CreateError = require('nu-error');

const ExampleError = CreateError('ExampleError');

throw ExampleError('This is an example!'); // throws ExampleError: This is an example!
const CreateError = require('nu-error');

const ExampleError = CreateError('ExampleError');

try {
  throw ExampleError('!', {
    extra: 'ExtraData',
  });
} catch (e) {
  console.log(e.extra); // 'ExtraData'
}

License

MIT