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