boomify

    0.0.1 • Public • Published

    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

    Install

    npm i boomify

    DownloadsWeekly Downloads

    189

    Version

    0.0.1

    License

    Apache-2.0

    Last publish

    Collaborators

    • avatar