# error-class

> Typed errors that closely emulate the native Error class.

Latest version **2.0.2** (published 2018-09-29) · MIT license · 0 weekly downloads

## Install

```sh
npm install error-class
pnpm add error-class
yarn add error-class
bun add 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 | 2.0.2 |
| Published | 2018-09-29 |
| First published | 2015-06-25 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 6 |
| Maintainers | daliwali |
| Keywords | error, type, typed, custom, native |

## Links

- npm: https://www.npmjs.com/package/error-class
- Repository: https://github.com/daliwali/error-class
- Homepage: https://github.com/daliwali/error-class#readme
- Issues: https://github.com/daliwali/error-class/issues
- npm.io page: https://npm.io/package/error-class

## 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

- 2.0.2 (latest) — 2018-09-29
- 2.0.1 — 2016-06-04
- 2.0.0 — 2015-11-20
- 1.1.1 — 2015-09-28
- 1.1.0 — 2015-09-07
- 1.0.8 — 2015-08-25
- 1.0.7 — 2015-08-25
- 1.0.6 — 2015-08-25
- 1.0.5 — 2015-07-23
- 1.0.4 — 2015-06-25
- 1.0.3 — 2015-06-25
- 1.0.2 — 2015-06-25
- 1.0.1 — 2015-06-25
- 1.0.0 — 2015-06-25

## README

# Error Class

[![Build Status](https://img.shields.io/travis/sapeien/error-class/master.svg?style=flat-square)](https://travis-ci.org/sapeien/error-class)
[![npm Version](https://img.shields.io/npm/v/error-class.svg?style=flat-square)](https://www.npmjs.com/package/error-class)
[![License](https://img.shields.io/npm/l/error-class.svg?style=flat-square)](https://raw.githubusercontent.com/sapeien/error-class/master/LICENSE)

This module provides typed errors that closely emulate the native `Error` class to a pedantic degree.

```
$ npm install error-class
```


## Usage

The default export is a function that accepts only one argument, the name of the typed error.

```js
const errorClass = require('error-class')
const SpecialError = errorClass('SpecialError')
const instance = new SpecialError('foobar')
instance.message // 'foobar'
```


## Details

```js
const errorClass = require('error-class')
const HumanError = errorClass('HumanError')

const hungryError = new HumanError('I\'m hungry!')
hungryError.message // 'I'm hungry!'
hungryError.stack // Platform-specific error stack trace.
hungryError.hasOwnProperty('name') // false
hungryError.hasOwnProperty('message') // true
hungryError.hasOwnProperty('stack') // true

// Just like native errors, it doesn't require using `new`.
const thirstyError = HumanError('I\'m thirsty!')
Object.keys(thirstyError).length === 0 // True, all properties are non-enumerable.
Object.keys(Object.getPrototypeOf(instance)).length === 0 // Prototype non-enumerable.
thirstyError.constructor === HumanError // True.
thirstyError instanceof Error // True, errors inherit from native `Error` class.
thirstyError instanceof HumanError // Also true, of course.
```


## License

This software is licensed under the [MIT License](https://github.com/sapeien/error-class/blob/master/LICENSE).

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