0.0.5 • Published 7 years ago

koa-handle-error v0.0.5

Weekly downloads
51
License
MIT
Repository
-
Last release
7 years ago

koa-handle-error

npm version CircleCI

Error handler Middleware for Koa@2.x

Installation

npm install koa-handle-error

Usage

IMPORTANT: handleError must register first as Koa middleware!

const Koa = require('koa');
const handleError = require('koa-handle-error');
const app = new Koa();

const onError = err => {
  console.error(err);
};

app.use(handleError(onError));  // must register first!
app.use(someMiddleware());
app.use(otherMiddleware());

API

handleError(onError: Function): (context: Koa.Context, next: () => Promise) => void

Returns a Koa middleware.

onError will called with the error when some error occured.

License

MIT