# koa-any-error

> 错误提示

Latest version **1.0.1** (published 2018-02-08) · MIT license · 0 weekly downloads

## Install

```sh
npm install koa-any-error
pnpm add koa-any-error
yarn add koa-any-error
bun add koa-any-error
```

## 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 | 1.0.1 |
| Published | 2018-02-08 |
| First published | 2017-12-11 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 5.5 KB |
| Known vulnerabilities | 0 (+2 in 1 direct dependencies) |
| Install scripts | no |
| Author | lynn.wang |
| Maintainers | lynn.wang |
| Keywords | koa, error |

## Links

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

## Dependencies (2)

- [pug](https://npm.io/package/pug.md) ^2.0.0-rc.4
- [consolidate](https://npm.io/package/consolidate.md) ^0.15.0

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

- 1.0.1 (latest) — 2018-02-08
- 1.0.0 — 2017-12-11

## README

# koa-any-error

##install

```bash
$ npm install koa-any-error --save
```

##errorFormats

```
{
  json(error,ctx,options){return {}},
  html(error,ctx,options){return ''},
  text(error,ctx,options){return ''}
}
```

## options

```
{
  accepts:['json', 'html', 'text'],
  isDev:true,
  method:(error,ctx,options)=>{

  }
}
```

```js
// dependencies
const Koa = require("koa");
const error = require("koa-any-error");
const app = new Koa();

const errorFormats = {
    json(err, ctx, opts) {
        logger.error(`throw ::: error : ${err.stack || err}`);
        const status = err.status || err.statusCode || 500;
        const result = {
            code: err.code || status,
            message: status,
            message: err.message,
            success: false,
            reason: "Unexpected"
        };
        if (env === "dev") {
            result["stack"] = err.stack;
        }
        return result;
    }
};

// middleware
app.use(error(errorFormats, options));
```

## notes

> 请务必在初始化在 koa 中间件的第一顺位 , 避免不必要问题

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