error-create

0.1.0 • Public • Published

error-create

Utility for creating custom JavaScript errors

Usage

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

Installation

$ npm install error-create

To port it to Browser or any other (non CJS) environment, use your favorite CJS bundler. No favorite yet? Try: Browserify, Webmake or Webpack

Tests Build Status

$ npm test

Dependents (2)

Package Sidebar

Install

npm i error-create

Weekly Downloads

2

Version

0.1.0

License

MIT

Last publish

Collaborators

  • medikoo