The very outer middleware of Koa to handle every response of every request.
yarn add koa-final-response or
npm install koa-final-response --save
const path = ;// Error object, see// We recommand to use Boom as the standard object for error responsesconst Boom = ;const Koa = ;const mountRoutes = ;const finalResp = ;const app = ;// this middleware should be added before router worksapp;// mount routes, see;app;
How to return results
For normal responses, you can pass your result data to
ctx.bodydirectly just following the standard Koa way;
For error responses, we recommend you use Boom to pass those expected errors like
throw Boom.unauthorized('invalid password'). Besides, any unexpected errors and non-Boom errors thrown by yourself will also be catched and handled well as you want.
You are welcomed to review test.js and controllers dir in this project for more information of usage.