error-create
v0.1.0
Published
Abstraction for creating custom JavaScript errors
Downloads
24
Maintainers
Readme
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(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 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
$ npm test