# @bonjourjohn/app-error

> This is a very simple error wrapper for any express or koa app

Latest version **2.0.2** (published 2022-05-14) · ISC license · 0 weekly downloads

## Install

```sh
npm install @bonjourjohn/app-error
pnpm add @bonjourjohn/app-error
yarn add @bonjourjohn/app-error
bun add @bonjourjohn/app-error
```

## Health

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

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

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.2 |
| Published | 2022-05-14 |
| First published | 2018-07-31 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 2.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | ESPIAU Nicolas |
| Maintainers | bonjourjohn |

## Links

- npm: https://www.npmjs.com/package/@bonjourjohn/app-error
- Repository: https://github.com/nicolasespiau/app-error
- Homepage: https://github.com/nicolasespiau/app-error#readme
- Issues: https://github.com/nicolasespiau/app-error/issues
- npm.io page: https://npm.io/package/@bonjourjohn/app-error

## Recent versions

- 2.0.2 (latest) — 2022-05-14
- 2.0.1 — 2022-05-14
- 2.0.0 — 2022-05-14
- 1.0.0 — 2018-07-31

## README

# AppError

## Install

`npm i -S @bonjourjohn/app-error`

## Usage

With [koa](http://koajs.com/):

```javascript
const koa = require('koa');
const AppError = require('@bonjourjohn/app-error');

const app = new koa();

app.use(async (ctx, next) => {
  try {
    await next();
  } catch (err) {
    //if caught error is not AppError, convert it
    if (!(err instanceOf AppError)) {
      err = AppError.fromError(err);
    }

    // will only respond with JSON
    ctx.status = err.errno;
    ctx.body = {
      errno: err.errno,
      error: err.error
    };
  }
});

[...] //rest of your code
```

## Testing

Run `npm test` after `npm install`.

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