1.0.0 • Published 5 years ago

@nioh/error v1.0.0

Weekly downloads
-
License
ISC
Repository
-
Last release
5 years ago

Midddleware: error

Installation

Install with npm

npm i @nioh/error

How to use

import * as Koa from 'koa'
import * as error from '@server/error'

const app = new Koa()

app.use(error({
  output: 'html'
}))

app.use(ctx => {
  if (ctx.request.path === '/') {
    ctx.body = 'ok'
  }
  if (ctx.request.path === '/a') {
    ctx.notExistedFn() // throw error
    ctx.body = '<html><body>tee</body></html>'
  }
})

app.listen(3000)

example with log

app.on('error', (err, ctx) => {
  debug('APP ERROR: ', ctx)
  ctx && ctx.log && ctx.log.error(err)
})

ChangeLog

Tests

npm test

License

2020@ROEI