1.0.2 • Published 6 years ago

koa-json-error-handler v1.0.2

Weekly downloads
17
License
MIT
Repository
github
Last release
6 years ago

koa-json-error-handler

Koa middleware to convert all HTTP error message to JSON response

Usage

const Koa = require('koa');
const jsonErrorHandler = require('koa-json-error-handler');

const app = new Koa();

app
    .use(jsonErrorHandler)
    .listen(8080);

app.on('error', (err, ctx) => {
    console.log('HTTP error', ctx.status, err);
});

The body of the response will be

{
    "result": false,
    "reason": "HTTP Error 404: Not Found"
}