Skip to content

Yoctol/koa-final-handler

Repository files navigation

koa-final-handler

Build Status npm

Final handler middleware for koa

Installation

Install using npm:

npm install @yoctol/koa-final-handler

Usage

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');
});

Response Body

The middleware will append error object on response body when NODE_ENV is development.

const { error } = response.body;

Error Reporting

const handleErrorReporting = (error, ctx) => {
  /* your error reporting handler */
};

app.on('error', handleErrorReporting);