# layerr

> Error wrapping utility for NodeJS and the browser

Latest version **3.0.0** (published 2024-04-22) · MIT license · 0 weekly downloads

## Install

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

## Health

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

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.0.0 |
| Published | 2024-04-22 |
| First published | 2020-08-27 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM |
| Dependencies | 0 |
| Unpacked size | 9.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | Perry Mitchell |
| Maintainers | perrymitchell |
| Keywords | error, verror, err, nerror, exception, wrapper, extend |

## Links

- npm: https://www.npmjs.com/package/layerr
- Repository: https://github.com/perry-mitchell/layerr
- Homepage: https://github.com/perry-mitchell/layerr#readme
- Issues: https://github.com/perry-mitchell/layerr/issues
- npm.io page: https://npm.io/package/layerr

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

- 3.0.0 (latest) — 2024-04-22
- 1.0.0-r1 (next) — 2022-12-12
- 2.1.0 — 2024-04-18
- 2.0.1 — 2023-07-17
- 2.0.0 — 2023-02-13
- 1.0.0 — 2022-12-12
- 0.2.0-r1 — 2022-12-12
- 0.1.2 — 2020-08-29
- 0.1.1 — 2020-08-29
- 0.1.0 — 2020-08-27

## README

# Layerr

> Errors, with.. layers..

A NodeJS and Web `Error` wrapping utility, based heavily on [VError](https://github.com/joyent/node-verror), but without all the extras and dependencies on Node core utilities. Written in Typescript, compiled to JavaScript and suitable for bundling in the browser.

Uses no dependencies, minifies well and is a great way to wrap errors as they propagate through complex applications (such as Express services, for instance).

_Layerr is an ESM library, and as such you need a compatible environment in which to install and use it._

## Installation

Install by running: `npm install layerr`.

## Usage

Use it as a regular error:

```typescript
const { Layerr } = require("layerr");

throw new Layerr("Test error");
```

Or use it to wrap errors:

```typescript
doSomething().catch((err) => {
    throw new Layerr(err, "Failed doing something");
});
```

Layerr's can have info attached:

```typescript
const { Layerr } = require("layerr");

function somethingElse() {
    throw new Layerr(
        {
            info: {
                code: 123,
            },
        },
        "Problem"
    );
}

somethingElse().catch((err: Layerr) => {
    const { code } = Layerr.info(err);
    // code === 123
});
```

### Global Name

By default Layerr names all created errors as `Layerr`. You can change this name by calling `setGlobalName`, and revert it by passing `null` to this function:

```typescript
import { Layerr, setGlobalName } from "layerr";

setGlobalName("CustomError");

const err = new Layerr("My error");

err.name; // "CustomError"

throw err;
// Uncaught Layerr [CustomError]: My error
```

## Support

Layerr (v3) supports NodeJS 16 onwards. It should also support all major+current browsers, once compiled/bundled.

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