# create-error-class

> Create Error classes

Latest version **3.0.2** (published 2016-04-05) · MIT license · 0 weekly downloads

## Install

```sh
npm install create-error-class
pnpm add create-error-class
yarn add create-error-class
bun add create-error-class
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.0.2 |
| Published | 2016-04-05 |
| First published | 2015-07-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=0.10.0 |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 40 |
| Author | Vsevolod Strukchinsky |
| Maintainers | floatdrop |

## Links

- npm: https://www.npmjs.com/package/create-error-class
- Repository: https://github.com/floatdrop/create-error-class
- Issues: https://github.com/floatdrop/create-error-class/issues
- npm.io page: https://npm.io/package/create-error-class

## Dependencies (1)

- [capture-stack-trace](https://npm.io/package/capture-stack-trace.md) ^1.0.0

## Recent versions

- 3.0.2 (latest) — 2016-04-05
- 3.0.1 — 2016-02-25
- 3.0.0 — 2015-12-06
- 2.0.1 — 2015-07-27
- 2.0.0 — 2015-07-24
- 1.0.0 — 2015-07-19

## README

# create-error-class [![Build Status](https://travis-ci.org/floatdrop/create-error-class.svg?branch=master)](https://travis-ci.org/floatdrop/create-error-class)

> Create error class


## Install

```
$ npm install --save create-error-class
```


## Usage

```js
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:

```js
var MyError = createErrorClass('MyError');

new MyError('Something gone wrong!').message; // => 'Something gone wrong!'
```

## License

MIT © [Vsevolod Strukchinsky](http://github.com/floatdrop)

---
_Source: https://npm.io/package/create-error-class · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
