Skip to content

axross/koa-handle-error

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

koa-handle-error

npm version CircleCI

Error handler Middleware for [email protected]

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