# createerror

> Helper for creating easily extensible and subclassable JavaScript Error classes.

Latest version **1.3.0** (published 2017-08-24) · 0 weekly downloads

## Install

```sh
npm install createerror
pnpm add createerror
yarn add createerror
bun add createerror
```

## 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 | 1.3.0 |
| Published | 2017-08-24 |
| First published | 2012-09-01 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >= 0.2.0 |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 8 |
| Author | Andreas Lind Petersen |
| Maintainers | maartenwinter, papandreou |
| Keywords | errors, error, class, errorclass |

## Links

- npm: https://www.npmjs.com/package/createerror
- Repository: https://github.com/One-com/node-createerror
- Homepage: https://github.com/One-com/node-createerror#readme
- Issues: https://github.com/One-com/node-createerror/issues
- npm.io page: https://npm.io/package/createerror

## Alternatives

- [@sentry/react-native](https://npm.io/package/@sentry/react-native.md) — 2.6M weekly downloads
- [@ardatan/aggregate-error](https://npm.io/package/@ardatan/aggregate-error.md) — 708.1K weekly downloads
- [custom-error-generator](https://npm.io/package/custom-error-generator.md) — 2.0K weekly downloads
- [@technik-sde/prosemirror-recreate-transform](https://npm.io/package/@technik-sde/prosemirror-recreate-transform.md) — 1.5K weekly downloads
- [@suchipi/error-utils](https://npm.io/package/@suchipi/error-utils.md) — 78 weekly downloads

## Recent versions

- 1.3.0 (latest) — 2017-08-24
- 1.2.0 — 2017-05-01
- 1.1.0 — 2016-02-21
- 1.0.1 — 2015-07-21
- 1.0.0 — 2015-06-07
- 0.5.1 — 2014-12-01
- 0.5.0 — 2014-09-22
- 0.4.1 — 2013-09-19
- 0.4.0 — 2013-09-06
- 0.3.0 — 2013-09-03
- 0.2.0 — 2013-06-03
- 0.1.0 — 2013-03-20
- 0.0.1 — 2012-09-01

## README

node-createerror
================

Helper for creating easily extensible and subclassable JavaScript Error classes.

Installation
------------

Make sure you have node.js and npm installed, then run:

    npm install createerror

Usage
-----

    var createError = require('createerror');

    var MyError = createError({
        name: 'MyError',
        // Used when no message is handed to the constructor:
        message: 'A slightly longer description of the error'
    });

Instances can carry extra data about the error:

    try {
        throw new MyError({
            message: "The message", // Not mandatory
            data: {disallowedIds: [1, 3, 4, 6]}
        });
    } catch(e) {
        console.warn(e.data); // {disallowedIds: [1, 3, 4, 6]}
    }

Inheriting from an existing Error class (the Error classes in the
[httpErrors](https://github.com/One-com/node-httperrors)  module also use
`createError`):

    var httpErrors = require('httperrors');

    var NotFoundUnderTheBedError = createError({
        name: 'NotFoundUnderTheBed',
        message: 'I looked under the bed, but it was not found'
    }, httpErrors.NotFound);

Instances of this error walk and quack like `httpErrors.NotFound` instances, of course:

    var ohDear = new NotFoundUnderTheBedError('No monsters today');
    console.warn(ohDear.NotFound); // true
    console.warn(ohDear.NotFoundUnderTheBed); // true


License
-------

3-clause BSD license -- see the `LICENSE` file for details.

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