|
|
3 سال پیش | |
|---|---|---|
| .. | ||
| templates | 3 سال پیش | |
| History.md | 3 سال پیش | |
| LICENSE | 3 سال پیش | |
| README.md | 3 سال پیش | |
| index.js | 3 سال پیش | |
| package.json | 3 سال پیش | |
an error handler for koa, hack ctx.onerror.
different with koa-error:
ctx.onerror, so if we want to handle all
errors in one place, the only way i can see is to hack ctx.onerror.npm install koa-onerror
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');
});
onerror(app, options);
check out default handler to write your own handler.
koa-onerror will automatic set err.status as response status code, and err.headers as response headers.