Name | Date | Size | #Lines | LOC | ||
---|---|---|---|---|---|---|
.. | - | - | ||||
index.js | D | 12-May-2024 | 915 | 45 | 35 | |
license | D | 12-May-2024 | 1.1 KiB | 22 | 17 | |
package.json | D | 12-May-2024 | 1.5 KiB | 61 | 60 | |
readme.md | D | 12-May-2024 | 1.1 KiB | 55 | 31 |
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