An open API service indexing awesome lists of open source software.

https://github.com/brian9206/koa-json-error-handler

Koa JSON Error Handler Middleware
https://github.com/brian9206/koa-json-error-handler

koa middleware

Last synced: 2 months ago
JSON representation

Koa JSON Error Handler Middleware

Awesome Lists containing this project

README

        

# koa-json-error-handler
Koa middleware to convert all HTTP error message to JSON response

## Usage
```js
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
```json
{
"result": false,
"reason": "HTTP Error 404: Not Found"
}
```