@robotsandpencils/koa-errors

0.1.3 • Public • Published

koa-errors

tests Coverage Status

@robotsandpencils/koa-errors is a simple koa middleware for handling error states (i.e. 500 errors). It's primary usage is to produce human, and program readable 500 errors that only include stack traces in development environments.

Usage

Using pnpm:

$ pnpm add @robotsandpencils/koa-errors

Using npm:

$ npm install --save @robotsandpencils/koa-errors

Using yarn:

$ yarn add @robotsandpencils/koa-errors
const { e500 } = require('@robotsandpencils/koa-errors')
const Koa = require('koa')
const Router = require('koa-router')

const app = new Koa()
const router = new Router()

app.on('error', (err, ctx) => {
  console.log('uncaught_koa_error', err, ctx)
})

app.use(e500({
  showStack: process.env.NODE_ENV === 'local',
}))

router.get('/boom', async (ctx) => {
  throw new Error('BOOM!')
})

app.use(router.routes())
app.listen(3000)

Arguments

@robotsandpencils/koa-errors accepts the following arguments:

  • showStack: whether or not to show the stack trace in the response body. Always set this to false in publically accessible environments, such as production.

Readme

Keywords

Package Sidebar

Install

npm i @robotsandpencils/koa-errors

Weekly Downloads

1

Version

0.1.3

License

MIT

Unpacked Size

11.8 kB

Total Files

8

Last publish

Collaborators

  • losandes
  • rnp