.gitignore added
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / create-error-class / 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
16 var createErrorClass = require('create-error-class');
17
18 var HTTPError = createErrorClass('HTTPError', function (props) {
19         this.message = 'Status code is ' + props.statusCode;
20 });
21
22 throw new HTTPError({statusCode: 404});
23 ```
24
25
26 ## API
27
28 ### createErrorClass(className, [setup])
29
30 Return constructor of Errors with `className`.
31
32 #### className
33
34 *Required*  
35 Type: `string`
36
37 Class name of Error Object. Should contain characters from `[0-9a-zA-Z_$]` range.
38
39 #### setup
40 Type: `function`
41
42 Setup function, that will be called after each Error object is created from constructor with context of Error object.
43
44 By default `setup` function sets `this.message` as first argument:
45
46 ```js
47 var MyError = createErrorClass('MyError');
48
49 new MyError('Something gone wrong!').message; // => 'Something gone wrong!'
50 ```
51
52 ## License
53
54 MIT © [Vsevolod Strukchinsky](http://github.com/floatdrop)