Skip to content
Create Error classes
Branch: master
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.editorconfig Initial commit Jul 19, 2015
.gitattributes Initial commit Jul 19, 2015
.gitignore Initial commit Jul 19, 2015
.jshintrc Initial commit Jul 19, 2015
.travis.yml Initial commit Jul 19, 2015
index.js remove duplicate name property assignment Feb 25, 2016
license
package.json 3.0.2 Apr 5, 2016
readme.md Update readme.md Sep 10, 2015
test.js Add logic to capture message within default setup Sep 10, 2015

readme.md

create-error-class Build Status

Create error class

Install

$ npm install --save create-error-class

Usage

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

Required
Type: string

Class name of Error Object. Should contain characters from [0-9a-zA-Z_$] range.

setup

Type: function

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

MIT © Vsevolod Strukchinsky

You can’t perform that action at this time.