koa-exception-handler
Customizable koa exception (error) handling middleware
Installation
yarn add koa-exception-handler
Usage
const Koa = const koaException = const app = app
options
options.logger
Customize logger
function.
- Type:
function
- Default:
console.error
options.production
Specifies whether it is a production environment that controls the behavior of the middleware when an error occurs on the server side.
- Type:
boolean
- Default:
process.env.NODE_ENV !== 'development'
When options.production
is true
, if an error occurs on the server, the options.fallback
function is executed without sending an error to the client. Of course, you can implement the behavior you expect in options.fallback
.
optioins.clientErrorHandler
The handler that is executed when an error occurs on the client.
-
Type:
function
-
Default:
undefined
-
arguments:
- ctx
Koa context
- err
error
- Instance ofError
- ctx
-
example:
app
optioins.serverErrorHandler
In a non-production environment, the handler executed when an error occurs on the server side.
- Type:
function
- Default:
undefined
- arguments:
- ctx
Koa context
- err
error
- Instance ofError
- ctx
Usage reference optioins.clientErrorHandler
.
optioins.fallback
Similar to optioins.serverErrorHandler
, except that optioins.fallback
is a handler that is executed in the production environment when an error occurs on the server side.
- Type:
function
- Default:
undefined
- arguments:
- ctx
Koa context
- err
error
- Instance ofError
- ctx