boom
Advanced tools
Comparing version 1.0.2 to 1.1.0
@@ -73,2 +73,33 @@ // Load modules | ||
// Return custom keys added to the error root or response.payload | ||
internals.Boom.prototype.decorations = function () { | ||
var decoration = {}; | ||
var rootKeys = Object.keys(this); | ||
for (var i = 0, il = rootKeys.length; i < il; ++i) { | ||
var key = rootKeys[i]; | ||
if (typeof this[key] !== 'function' && | ||
key[0] !== '_' && | ||
['isBoom', 'response', 'message'].indexOf(key) === -1) { | ||
decoration[key] = this[key]; | ||
} | ||
} | ||
var responseKeys = Object.keys(this.response.payload); | ||
for (i = 0, il = responseKeys.length; i < il; ++i) { | ||
var key = responseKeys[i]; | ||
if (['code', 'error', 'message'].indexOf(key) === -1) { | ||
decoration.response = decoration.response || {}; | ||
decoration.response[key] = this.response.payload[key]; | ||
} | ||
} | ||
return decoration; | ||
}; | ||
// 4xx Client Errors | ||
@@ -75,0 +106,0 @@ |
{ | ||
"name": "boom", | ||
"description": "HTTP-friendly error objects", | ||
"version": "1.0.2", | ||
"version": "1.1.0", | ||
"repository": "git://github.com/spumko/boom", | ||
@@ -6,0 +6,0 @@ "main": "index", |
@@ -42,2 +42,20 @@ // Load modules | ||
describe('#decorations', function () { | ||
it('returns custom members', function (done) { | ||
var error = Boom.badRequest('Custom'); | ||
error.a1 = 'Have an A1 day'; | ||
error.response.payload.walt = 'heisenberg'; | ||
expect(error.decorations()).to.deep.equal({ | ||
a1: 'Have an A1 day', | ||
response: { | ||
walt: 'heisenberg' | ||
} | ||
}); | ||
done(); | ||
}); | ||
}); | ||
describe('#isBoom', function () { | ||
@@ -44,0 +62,0 @@ |
53415
541