November 2018
Beginner
132 pages
2h 57m
English
It is recommended that you emit an error on the application itself. This is useful for centralized error reporting or logging. This also helps to retain the default behavior of Koa for errors. Errors can be emitted using the ctx.app.emit() method:
app.use(async (ctx, next) => { try { await next(); } catch (err) { ctx.status = err.status || 500; ctx.body = err.message; ctx.app.emit('error', err, ctx); } });
Read now
Unlock full access