boom
Advanced tools
Comparing version 2.7.2 to 2.8.0
@@ -102,5 +102,11 @@ // Load modules | ||
wwwAuthenticate = scheme; | ||
if (attributes || message) { | ||
err.output.payload.attributes = {}; | ||
} | ||
if (attributes) { | ||
var names = Object.keys(attributes); | ||
for (i = 0, il = names.length; i < il; ++i) { | ||
var name = names[i]; | ||
if (i) { | ||
@@ -110,3 +116,3 @@ wwwAuthenticate += ','; | ||
var value = attributes[names[i]]; | ||
var value = attributes[name]; | ||
if (value === null || | ||
@@ -117,3 +123,4 @@ value === undefined) { // Value can be zero | ||
} | ||
wwwAuthenticate += ' ' + names[i] + '="' + Hoek.escapeHeaderAttribute(value.toString()) + '"'; | ||
wwwAuthenticate += ' ' + name + '="' + Hoek.escapeHeaderAttribute(value.toString()) + '"'; | ||
err.output.payload.attributes[name] = value; | ||
} | ||
@@ -127,2 +134,3 @@ } | ||
wwwAuthenticate += ' error="' + Hoek.escapeHeaderAttribute(message) + '"'; | ||
err.output.payload.attributes.error = message; | ||
} | ||
@@ -129,0 +137,0 @@ else { |
{ | ||
"name": "boom", | ||
"description": "HTTP-friendly error objects", | ||
"version": "2.7.2", | ||
"version": "2.8.0", | ||
"repository": "git://github.com/hapijs/boom", | ||
"main": "index", | ||
"main": "lib/index.js", | ||
"keywords": [ | ||
@@ -8,0 +8,0 @@ "error", |
@@ -85,3 +85,8 @@ ![boom Logo](https://raw.github.com/hapijs/boom/master/images/boom.png) | ||
- an array of string values. These values will be separated by ', ' and set to the 'WWW-Authenticate' header. | ||
- `attributes` - an object of values to use while setting the 'WWW-Authenticate' header. This value is only used when `schema` is a string, otherwise it is ignored. Every key/value pair will be included in the 'WWW-Authenticate' in the format of 'key="value"'. `null` and `undefined` will be replaced with an empty string. If `attributes` is set, `message` will be used as the 'error' segment of the 'WWW-Authenticate' header. If `message` is unset, the 'error' segment of the header will not be present and `isMissing` will be true on the error object. | ||
- `attributes` - an object of values to use while setting the 'WWW-Authenticate' header. This value is only used | ||
when `schema` is a string, otherwise it is ignored. Every key/value pair will be included in the | ||
'WWW-Authenticate' in the format of 'key="value"' as well as in the response payload under the `attributes` key. | ||
`null` and `undefined` will be replaced with an empty string. If `attributes` is set, `message` will be used as | ||
the 'error' segment of the 'WWW-Authenticate' header. If `message` is unset, the 'error' segment of the header | ||
will not be present and `isMissing` will be true on the error object. | ||
@@ -115,3 +120,6 @@ If either `scheme` or `attributes` are set, the resultant `Boom` object will have the 'WWW-Authenticate' header set for the response. | ||
"error": "Unauthorized", | ||
"message": "invalid password" | ||
"message": "invalid password", | ||
"attributes": { | ||
"error": "invalid password" | ||
} | ||
}, | ||
@@ -133,3 +141,9 @@ "headers" { | ||
"error": "Unauthorized", | ||
"message": "invalid password" | ||
"message": "invalid password", | ||
"attributes": { | ||
"error": "invalid password", | ||
"ttl": 0, | ||
"cache": "", | ||
"foo": "bar" | ||
} | ||
}, | ||
@@ -136,0 +150,0 @@ "headers" { |
@@ -203,2 +203,3 @@ // Load modules | ||
expect(err.output.headers['WWW-Authenticate']).to.equal('Test a="1", b="something", c="", d="0", error="boom"'); | ||
expect(err.output.payload.attributes).to.deep.equal({ a: 1, b: 'something', c: '', d: 0, error: 'boom' }); | ||
done(); | ||
@@ -205,0 +206,0 @@ }); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
68440
602
598
9