# generic-errors

> Generic errors with common http codes

Latest version **2.3.1** (published 2022-04-18) · MIT license · 0 weekly downloads

## Install

```sh
npm install generic-errors
pnpm add generic-errors
yarn add generic-errors
bun add generic-errors
```

## 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.3.1 |
| Published | 2022-04-18 |
| First published | 2015-06-22 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 29.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Maurice Butler |
| Maintainers | mauricebutler |
| Keywords | error, errors, http, custom, generic, code, 404, 200, teapot |

## Links

- npm: https://www.npmjs.com/package/generic-errors
- Repository: https://github.com/MauriceButler/generic-errors
- Issues: https://github.com/MauriceButler/generic-errors/issues
- npm.io page: https://npm.io/package/generic-errors

## Dependencies (1)

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

## 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.3.1 (latest) — 2022-04-18
- 2.3.0 — 2021-07-15
- 2.2.1 — 2020-06-18
- 2.2.0 — 2020-06-17
- 2.1.0 — 2018-01-12
- 2.0.2 — 2016-03-09
- 2.0.1 — 2015-12-07
- 2.0.0 — 2015-07-10
- 1.0.1 — 2015-06-22
- 1.0.0 — 2015-06-22

## README

# generic-errors

Generic error constructors with common http codes.

Also doesn't pollute the stack with its own depth.

## Usage

Install:

```
npm install generic-errors
```

Require the errors:

```JavaScript
const errors = require('generic-errors');
```

Use an error:

```JavaScript
const notFound = new errors.NotFound('Could not find the thing');
```

Add additional Properties to the error

```JavaScript
const unprocessable = new errors.Unprocessable({ message: 'Cant Process', fields: ['foo', bar] });
```

## Available constructors:

```
BaseError                       // 500 Use to make custom errors, easier to inherit from than Error
BadRequest                      // 400
Unauthorised                    // 401
Forbidden                       // 403
NotFound                        // 404
MethodNotAllowed                // 405
NotAcceptable                   // 406
ProxyAuthenticationRequired     // 407
RequestTimeout                  // 408
Conflict                        // 409
Gone                            // 410
LengthRequired                  // 411
PreconditionFailed              // 412
PayloadTooLarge                 // 413
URITooLong                      // 414
UnsupportedMediaType            // 415
RangeNotSatisfiable             // 416
ExpectationFailed               // 417
Teapot                          // 418
Unprocessable                   // 422
TooEarly                        // 425
UpgradeRequired                 // 426
PreconditionRequired            // 428
TooManyRequests                 // 429
RequestHeaderFieldsTooLarge     // 431
UnavailableForLegalReasons      // 451
NotImplemented                  // 501
BadGateway                      // 502
ServiceUnavailable              // 503
GatewayTimeout                  // 504
HTTPVersionNotSupported         // 505
VariantAlsoNegotiates           // 506
NotExtended                     // 510
NetworkAuthenticationRequired   // 511
```

## Detection

After serialization Generic Errors can still be detected using the `isGenericError` function attacted to the BaseError constructor.

```JavaScript
    const notFound = new errors.NotFound();
    const serializedError = JSON.parse(JSON.stringify(notFound));

    errors.BaseError.isGenericError(serializedError);  // true
```

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