Socket
Socket
Sign inDemoInstall

create-error-class

Package Overview
Dependencies
1
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    create-error-class

Create Error classes


Version published
Weekly downloads
1.9M
increased by4.93%
Maintainers
1
Install size
8.25 kB
Created
Weekly downloads
 

Readme

Source

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

FAQs

Last updated on 05 Apr 2016

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc