• Home
Name Date Size #Lines LOC

..--

index.jsD12-May-2024915 4535

licenseD12-May-20241.1 KiB2217

package.jsonD12-May-20241.5 KiB6160

readme.mdD12-May-20241.1 KiB5531

readme.md

1# create-error-class [![Build Status](https://travis-ci.org/floatdrop/create-error-class.svg?branch=master)](https://travis-ci.org/floatdrop/create-error-class)
2
3> Create error class
4
5
6## Install
7
8```
9$ npm install --save create-error-class
10```
11
12
13## Usage
14
15```js
16var createErrorClass = require('create-error-class');
17
18var HTTPError = createErrorClass('HTTPError', function (props) {
19	this.message = 'Status code is ' + props.statusCode;
20});
21
22throw new HTTPError({statusCode: 404});
23```
24
25
26## API
27
28### createErrorClass(className, [setup])
29
30Return constructor of Errors with `className`.
31
32#### className
33
34*Required*
35Type: `string`
36
37Class name of Error Object. Should contain characters from `[0-9a-zA-Z_$]` range.
38
39#### setup
40Type: `function`
41
42Setup function, that will be called after each Error object is created from constructor with context of Error object.
43
44By default `setup` function sets `this.message` as first argument:
45
46```js
47var MyError = createErrorClass('MyError');
48
49new MyError('Something gone wrong!').message; // => 'Something gone wrong!'
50```
51
52## License
53
54MIT © [Vsevolod Strukchinsky](http://github.com/floatdrop)
55