$ npm install koa-onerror
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);
options.all exist, ignore negotiationhtml or text, can redirect to another error pagecheck 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.
Made with contributors-img.
© 2010 - cnpmjs.org x YWFE | Home | YWFE