1.1.3 • Published 4 years ago

boomware v1.1.3

Weekly downloads
6
License
MIT
Repository
github
Last release
4 years ago

boomware

Opinionated Boom-based wrapper for asynchronous middleware (or handler) for Express, Connect, router, etc.

Installing

npm i --save boomware

Example

const boom = require('boom')
const boomware = require('boomware')
const express = require('express')

const app = express()

// Middleware can return a Promise (but it doesn't have to)
app.get('/async', boomware(async (req, res) => {
  if (Math.random() > 0.75) throw('Unexpected error!')
  if (Math.random() > 0.5) throw boom.serverUnavailable()
  res.send('OK!')
}))

app.use((err, req, res, next) => {
  console.error(err)
  res.status(err.output.statusCode).json(err.output.payload)
})

app.listen(3000)

API

boomware(fn)

Returns a middleware function that catches a thrown error, wraps it in an Boom.badImplementation if it's not already a Boom error, and passes it to the next() function. boomware handles the case whenfn return Promise, and the case when fn does not return a Promise.

Related work

License

MIT

1.1.3

4 years ago

1.1.2

4 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.0

6 years ago