0.0.1 • Published 7 years ago

boomify v0.0.1

Weekly downloads
150
License
Apache-2.0
Repository
github
Last release
7 years ago

boomify NPM version Build Status Dependency Status Coverage Status

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