5.0.1 • Published 5 months ago
koa-onerror v5.0.1
koa-onerror
an error handler for koa, hack ctx.onerror.
different with koa-error:
- we can not just use try catch to handle all errors, steams' and events'
errors are directly handle by
ctx.onerror
, so if we want to handle all errors in one place, the only way i can see is to hackctx.onerror
. - it is more customizable.
install
npm install koa-onerror
Usage
const fs = require('fs');
const Koa = require('koa');
const { onerror } = require('koa-onerror');
const app = new Koa();
onerror(app);
app.use(ctx => {
// foo();
ctx.body = fs.createReadStream('not exist');
});
Options
onerror(app, options);
- all: if
options.all
exist, ignore negotiation - text: text error handler
- json: json error handler
- html: html error handler
- redirect: if accept
html
ortext
, can redirect to another error page
check out default handler to write your own handler.
Status and Headers
koa-onerror
will automatic set err.status
as response status code, and err.headers
as response headers.
License
Contributors
Made with contributors-img.
5.0.1
5 months ago
5.0.0
5 months ago
4.2.0
3 years ago
4.1.0
7 years ago
4.0.1
7 years ago
4.0.0
8 years ago
3.1.0
8 years ago
3.0.2
8 years ago
3.0.1
9 years ago
3.0.0
9 years ago
2.1.0
9 years ago
2.0.0
9 years ago
1.3.1
9 years ago
1.3.0
9 years ago
1.2.1
10 years ago
1.2.0
11 years ago
1.1.0
11 years ago
1.0.3
11 years ago
1.0.2
11 years ago
1.0.1
11 years ago
1.0.0
11 years ago
0.0.2
11 years ago
0.0.1
11 years ago
0.0.0
11 years ago