error-create

Abstraction for creating custom JavaScript errors

npm install error-create
2 downloads in the last day
18 downloads in the last week
58 downloads in the last month

error-create

Create custom JavaScript errors

Usage

var MyCustomError = require('error-create')('MyCustomError');

try {
  throw new MyCustomError("My message", 'MY_CODE', { foo: 'bar' });
} catch (e) {
  console.log(e instanceof Error);         // true
  console.log(e instanceof MyCustomError); // true
  console.log(String(e));                  // 'MyCustomError: My message'
  console.log(e.code);                     // 'MY_CODE'
  console.log(e.foo);                      // 'bar'
}

Installation

NPM

In your project path:

$ npm install error-create
Browser

You can easily bundle error-create for browser with modules-webmake

Tests Build Status

$ npm test
npm loves you