Skip to contentpackage
create-error-class
v2.0.0Create Error classes
node >=0.10.02 depscjsopen source
- license
- MIT
- deps
- 2
- unpacked
- Unknown
- files
- Unknown
- node
- >=0.10.0
$npm install create-error-class@2.0.0 README
GitHub-flavored package documentation.
downloads
Across all versions.
Download trend unavailable.
compatibility
Runtime metadata.
install size
Estimated unpacked size across 2 packages.
3.4 kB
Includes dependencies.
dependencies
1 direct · 1 outdated
versions
Latest published Apr 5, 2016
contents
create-error-class 
Create error class
Install
$ npm install --save create-error-class
Usage
Jul 27, 2015
maintainers
Registry package owners.
var createErrorClass = require('create-error-class');
var HTTPError = createErrorClass('HTTPError', function (props) {
this.message = 'Status code is ' + props.statusCode;
});
throw new HTTPError({statusCode: 404});
API
createErrorClass(className, [setup])
Return constructor of Errors with className.
className
Class name of Error Object. Should contain characters from [0-9a-zA-Z_$] range.
setup
Setup function, that will be called after each Error object is created from constructor with context of Error object.
By default setup function sets this.message as first argument:
var MyError = createErrorClass('MyError');
new MyError('Something gone wrong!').message; // => 'Something gone wrong!'
License