boomify
v0.0.1
Published
A simple higher order component to handle errors using boom and express.
Downloads
6
Readme
boomify
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