boomify

A simple higher order component to handle errors using boom and express.

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
boomify
0.0.17 years ago7 years agoMinified + gzip package size for boomify in KB

Readme

A simple higher order component to handle errors using boom and express.

Installation

$ npm install --save boomify

Usage

var app = require('express')();
var boom = require('boom');
var boomify = require('boomify');

var ctrl = {
  findOne(req, res) => res.send(boom.notFound('could not find!')),
  morePractically(req, res) => {
    if(err) {
      // boomify will convert this to the appropriate response object
      return res.send(err); 
    }
    res.status(200);
    res.send({ foo: 'bar' });
  }
};

// boomify whole ctrl
app.get('/cats/findOne', boomify(ctrl).findOne);

// boomify a single method
boomify(ctrl, 'findOne');
app.get('/cats/findOne', ctrl.findOne);

// will convert boom.notFound to res.error(404); res.send(err.output.payload);

Tests

mocha test

License

Apache-2.0 © blugavere