Comparing version 4.2.0 to 4.3.0
@@ -76,2 +76,4 @@ 'use strict'; | ||
Hoek.assert(error instanceof Error, 'Cannot wrap non-Error object'); | ||
Hoek.assert(!error.isBoom || arguments.length === 1, 'Cannot provide statusCode or message with boom error'); | ||
return (error.isBoom ? error : internals.initialize(error, statusCode || 500, message)); | ||
@@ -89,2 +91,9 @@ }; | ||
if (message instanceof Error) { | ||
if (data) { | ||
message.data = data; | ||
} | ||
return exports.wrap(message, statusCode); | ||
} | ||
const error = new Error(message ? message : undefined); // Avoids settings null message | ||
@@ -176,20 +185,27 @@ Error.captureStackTrace(error, ctor); // Filter the stack to our external API | ||
if (attributes) { | ||
const names = Object.keys(attributes); | ||
for (let i = 0; i < names.length; ++i) { | ||
const name = names[i]; | ||
if (i) { | ||
wwwAuthenticate = wwwAuthenticate + ','; | ||
} | ||
if (typeof attributes === 'string') { | ||
wwwAuthenticate = wwwAuthenticate + ' ' + Hoek.escapeHeaderAttribute(attributes); | ||
err.output.payload.attributes = attributes; | ||
} | ||
else { | ||
const names = Object.keys(attributes); | ||
for (let i = 0; i < names.length; ++i) { | ||
const name = names[i]; | ||
if (i) { | ||
wwwAuthenticate = wwwAuthenticate + ','; | ||
} | ||
let value = attributes[name]; | ||
if (value === null || | ||
value === undefined) { // Value can be zero | ||
let value = attributes[name]; | ||
if (value === null || | ||
value === undefined) { // Value can be zero | ||
value = ''; | ||
value = ''; | ||
} | ||
wwwAuthenticate = wwwAuthenticate + ' ' + name + '="' + Hoek.escapeHeaderAttribute(value.toString()) + '"'; | ||
err.output.payload.attributes[name] = value; | ||
} | ||
wwwAuthenticate = wwwAuthenticate + ' ' + name + '="' + Hoek.escapeHeaderAttribute(value.toString()) + '"'; | ||
err.output.payload.attributes[name] = value; | ||
} | ||
} | ||
if (message) { | ||
@@ -332,2 +348,8 @@ if (attributes) { | ||
exports.teapot = function (message, data) { | ||
return internals.create(418, message, data, exports.teapot); | ||
}; | ||
exports.badData = function (message, data) { | ||
@@ -334,0 +356,0 @@ |
{ | ||
"name": "boom", | ||
"description": "HTTP-friendly error objects", | ||
"version": "4.2.0", | ||
"version": "4.3.0", | ||
"repository": "git://github.com/hapijs/boom", | ||
@@ -18,4 +18,4 @@ "main": "lib/index.js", | ||
"devDependencies": { | ||
"code": "3.x.x", | ||
"lab": "10.x.x", | ||
"code": "4.x.x", | ||
"lab": "13.x.x", | ||
"markdown-toc": "0.12.x" | ||
@@ -22,0 +22,0 @@ }, |
@@ -35,2 +35,3 @@ ![boom Logo](https://raw.github.com/hapijs/boom/master/images/boom.png) | ||
- [`Boom.expectationFailed([message], [data])`](#boomexpectationfailedmessage-data) | ||
- [`Boom.teapot([message], [data])`](#boomteapotmessage-data) | ||
- [`Boom.badData([message], [data])`](#boombaddatamessage-data) | ||
@@ -73,3 +74,2 @@ - [`Boom.locked([message], [data])`](#boomlockedmessage-data) | ||
## Helper Methods | ||
@@ -132,3 +132,3 @@ | ||
when `scheme` 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. | ||
'WWW-Authenticate' in the format of 'key="value"' as well as in the response payload under the `attributes` key. Alternatively value can be a string which is use to set the value of the scheme, for example setting the token value for negotiate header. If string is used message parameter must be null. | ||
`null` and `undefined` will be replaced with an empty string. If `attributes` is set, `message` will be used as | ||
@@ -176,2 +176,19 @@ the 'error' segment of the 'WWW-Authenticate' header. If `message` is unset, the 'error' segment of the header | ||
```js | ||
Boom.unauthorized(null, 'Negotiate', 'VGhpcyBpcyBhIHRlc3QgdG9rZW4='); | ||
``` | ||
Generates the following response: | ||
```json | ||
"payload": { | ||
"statusCode": 401, | ||
"error": "Unauthorized", | ||
"attributes": "VGhpcyBpcyBhIHRlc3QgdG9rZW4=" | ||
}, | ||
"headers" { | ||
"WWW-Authenticate": "Negotiate VGhpcyBpcyBhIHRlc3QgdG9rZW4=" | ||
} | ||
``` | ||
```js | ||
Boom.unauthorized('invalid password', 'sample', { ttl: 0, cache: null, foo: 'bar' }); | ||
@@ -518,2 +535,22 @@ ``` | ||
### `Boom.teapot([message], [data])` | ||
Returns a 418 I'm a Teapot error where: | ||
- `message` - optional message. | ||
- `data` - optional additional error data. | ||
```js | ||
Boom.teapot('sorry, no coffee...'); | ||
``` | ||
Generates the following response payload: | ||
```json | ||
{ | ||
"statusCode": 418, | ||
"error": "I'm a Teapot", | ||
"message": "Sorry, no coffee..." | ||
} | ||
``` | ||
### `Boom.badData([message], [data])` | ||
@@ -520,0 +557,0 @@ |
Sorry, the diff of this file is not supported yet
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
32595
287
761