Skip to content
Create Error classes
Branch: master
Clone or download
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
package.json 3.0.2 Apr 5, 2016 Update Sep 10, 2015
test.js Add logic to capture message within default setup Sep 10, 2015

create-error-class Build Status

Create error class


$ npm install --save create-error-class


var createErrorClass = require('create-error-class');

var HTTPError = createErrorClass('HTTPError', function (props) {
	this.message = 'Status code is ' + props.statusCode;

throw new HTTPError({statusCode: 404});


createErrorClass(className, [setup])

Return constructor of Errors with className.


Type: string

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


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!'


MIT © Vsevolod Strukchinsky

You can’t perform that action at this time.