onerror for koa extend.
$ npm install @koex/onerror
// See more in test
import onerror from '@koex/onerror';
import * as Koa from 'koa';
const app = new Koa();
app.use(onerror());
// fallback
app.use(async (ctx) => {
const error = new Error('Unauthorized');
(error as any).status = 401;
throw error;
});
app.listen(8000, '0.0.0.0', () => {
console.log('koa server start at port: 8000');
});