zoom
v0.0.2
Published
Like hapijs boom but for non-error return data
Downloads
254
Readme
Zoom
Provides a consitent interface that mirrors Boom
// Here's the code in full
'use strict';
function Zoom(data, statusCode) {
this.data = data;
this.statusCode = statusCode || 200;
}
Zoom.create = function(data) {
return new Zoom(data);
}
module.exports = Zoom;
Usage
function handler(request, reply) {
doAsync(function(err, result) {
if (err) {
return reply(Boom.badImplementation(err, 'Something went wrong'));
}
return Zoom.create(result);
})
}
// This would yield
{
"statusCode": 200,
"data": {
"foo": true,
"bar": 42
}
}
// If an error occured, the (Boom) response would look like
{
"statusCode": 400,
"error": "whatever",
"message": "Something went wrong",
}