# subclass-error

> Workaround for subclassing errors. Both instanceof and stack are functional.

Latest version **0.1.1** (published 2015-03-27) · MIT license · 0 weekly downloads

## Install

```sh
npm install subclass-error
pnpm add subclass-error
yarn add subclass-error
bun add subclass-error
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.1 |
| Published | 2015-03-27 |
| First published | 2014-01-05 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 4 |
| Author | David da Silva Contin |
| Maintainers | dasilvacontin |
| Keywords | error, subclass, instanceof, stack |

## Links

- npm: https://www.npmjs.com/package/subclass-error
- Repository: https://github.com/dasilvacontin/subclass-error
- Issues: https://github.com/dasilvacontin/subclass-error/issues
- npm.io page: https://npm.io/package/subclass-error

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

- 0.1.1 (latest) — 2015-03-27
- 0.1.0 — 2015-03-24
- 0.0.3 — 2015-03-22
- 0.0.2 — 2014-01-05
- 0.0.1 — 2014-01-05
- 0.0.0 — 2014-01-05

## README

subclass-error
==============

[![Build Status](https://travis-ci.org/dasilvacontin/subclass-error.svg)](https://travis-ci.org/dasilvacontin/subclass-error)


Workaround for subclassing errors. Both instanceof and stack are functional.

## Use:

```bash
$ npm install subclass-error
```

```js
var SubclassError = require('subclass-error');

var ClientError = SubclassError ("ClientError", {statusCode:400});
var ForbiddenError = SubclassError ("ForbiddenError", ClientError, {statusCode:403});

var clientErr = new ClientError ();

clientErr instanceof Error // true
clientErr instanceof ClientError // true
clientErr instanceof ForbiddenError // false
clientErr.statusCode // 400

var forbidErr = new ForbiddenError ();

forbidErr instanceof Error // true
forbidErr instanceof ClientError // true
forbidErr instanceof ForbiddenError // true
forbidErr.statusCode // 403

function hungry () {
	throw new ForbiddenError ("wow, much forbidden, very subclass");
}

hungry();
/* 
	ForbiddenError: wow, much forbidden, very subclass
	    at hungry (filePath:19:8)
	    etc expected stack
*/
```

### SubclassError(name, [error, properties])

Creates a new subclass of 'error' (if specified) or Error (by default). The instances of the new subclass will have the same properties as those provided in the optional 'properties' parameter.

### Notes:

I didn't find any other workaround in which both 'instanceof' and 'stack' work as you would expect, so I ended up creating this.

### License

MIT

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