Final handler middleware for koa
Install using npm:
npm install @yoctol/koa-final-handler
const Koa = require('koa');
const finalHandler = require('@yoctol/koa-final-handler');
const app = new Koa();
app.use(finalHandler());
/* using other middleware after this line */
app.use(auth());
app.use(route());
app.listen(8080, () => {
console.log('server is running on http://localhost:8080');
});
The middleware will append error object on response body when NODE_ENV
is development
.
const { error } = response.body;
const handleErrorReporting = (error, ctx) => {
/* your error reporting handler */
};
app.on('error', handleErrorReporting);