NPM Dependencies UPDATE
This commit is contained in:
1 parent
d3bc5e34f6
commit
5bfb4ff32a
732 files changed
+13367
-62155
No files matched your search
-18
@@ -1,18 +0,0 @@
|
||||
.idea
|
||||
*.iml
|
||||
npm-debug.log
|
||||
dump.rdb
|
||||
node_modules
|
||||
results.tap
|
||||
results.xml
|
||||
npm-shrinkwrap.json
|
||||
config.json
|
||||
.DS_Store
|
||||
*/.DS_Store
|
||||
*/*/.DS_Store
|
||||
._*
|
||||
*/._*
|
||||
*/*/._*
|
||||
coverage.*
|
||||
lib-cov
|
||||
|
||||
-8
@@ -1,8 +0,0 @@
|
||||
language: node_js
|
||||
|
||||
node_js:
|
||||
- 0.10
|
||||
- 4.0
|
||||
|
||||
sudo: false
|
||||
|
||||
-1
@@ -1 +0,0 @@
|
||||
Please view our [hapijs contributing guide](https://github.com/hapijs/hapi/blob/master/CONTRIBUTING.md).
|
||||
+3
-2
@@ -1,4 +1,5 @@
|
||||
Copyright (c) 2012-2014, Walmart and other contributors.
|
||||
Copyright (c) 2012-2017, Project contributors.
|
||||
Copyright (c) 2012-2014, Walmart.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
@@ -25,4 +26,4 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
* * *
|
||||
|
||||
The complete list of contributors can be found at: https://github.com/hapijs/boom/graphs/contributors
|
||||
The complete list of contributors can be found at: https://github.com/hapijs/boom/graphs/contributors
|
||||
+152
-44
@@ -2,11 +2,54 @@
|
||||
|
||||
HTTP-friendly error objects
|
||||
|
||||
[](http://travis-ci.org/hapijs/boom)
|
||||
[](http://travis-ci.org/hapijs/boom)
|
||||
[](https://www.npmjs.com/package/boom)
|
||||
|
||||
Lead Maintainer: [Adam Bretz](https://github.com/arb)
|
||||
|
||||
<!-- toc -->
|
||||
|
||||
- [Boom](#boom)
|
||||
- [Helper Methods](#helper-methods)
|
||||
- [`wrap(error, [statusCode], [message])`](#wraperror-statuscode-message)
|
||||
- [`create(statusCode, [message], [data])`](#createstatuscode-message-data)
|
||||
- [HTTP 4xx Errors](#http-4xx-errors)
|
||||
- [`Boom.badRequest([message], [data])`](#boombadrequestmessage-data)
|
||||
- [`Boom.unauthorized([message], [scheme], [attributes])`](#boomunauthorizedmessage-scheme-attributes)
|
||||
- [`Boom.paymentRequired([message], [data])`](#boompaymentrequiredmessage-data)
|
||||
- [`Boom.forbidden([message], [data])`](#boomforbiddenmessage-data)
|
||||
- [`Boom.notFound([message], [data])`](#boomnotfoundmessage-data)
|
||||
- [`Boom.methodNotAllowed([message], [data], [allow])`](#boommethodnotallowedmessage-data-allow)
|
||||
- [`Boom.notAcceptable([message], [data])`](#boomnotacceptablemessage-data)
|
||||
- [`Boom.proxyAuthRequired([message], [data])`](#boomproxyauthrequiredmessage-data)
|
||||
- [`Boom.clientTimeout([message], [data])`](#boomclienttimeoutmessage-data)
|
||||
- [`Boom.conflict([message], [data])`](#boomconflictmessage-data)
|
||||
- [`Boom.resourceGone([message], [data])`](#boomresourcegonemessage-data)
|
||||
- [`Boom.lengthRequired([message], [data])`](#boomlengthrequiredmessage-data)
|
||||
- [`Boom.preconditionFailed([message], [data])`](#boompreconditionfailedmessage-data)
|
||||
- [`Boom.entityTooLarge([message], [data])`](#boomentitytoolargemessage-data)
|
||||
- [`Boom.uriTooLong([message], [data])`](#boomuritoolongmessage-data)
|
||||
- [`Boom.unsupportedMediaType([message], [data])`](#boomunsupportedmediatypemessage-data)
|
||||
- [`Boom.rangeNotSatisfiable([message], [data])`](#boomrangenotsatisfiablemessage-data)
|
||||
- [`Boom.expectationFailed([message], [data])`](#boomexpectationfailedmessage-data)
|
||||
- [`Boom.teapot([message], [data])`](#boomteapotmessage-data)
|
||||
- [`Boom.badData([message], [data])`](#boombaddatamessage-data)
|
||||
- [`Boom.locked([message], [data])`](#boomlockedmessage-data)
|
||||
- [`Boom.preconditionRequired([message], [data])`](#boompreconditionrequiredmessage-data)
|
||||
- [`Boom.tooManyRequests([message], [data])`](#boomtoomanyrequestsmessage-data)
|
||||
- [`Boom.illegal([message], [data])`](#boomillegalmessage-data)
|
||||
- [HTTP 5xx Errors](#http-5xx-errors)
|
||||
- [`Boom.badImplementation([message], [data])` - (*alias: `internal`*)](#boombadimplementationmessage-data---alias-internal)
|
||||
- [`Boom.notImplemented([message], [data])`](#boomnotimplementedmessage-data)
|
||||
- [`Boom.badGateway([message], [data])`](#boombadgatewaymessage-data)
|
||||
- [`Boom.serverUnavailable([message], [data])`](#boomserverunavailablemessage-data)
|
||||
- [`Boom.gatewayTimeout([message], [data])`](#boomgatewaytimeoutmessage-data)
|
||||
- [F.A.Q.](#faq)
|
||||
|
||||
<!-- tocstop -->
|
||||
|
||||
# Boom
|
||||
|
||||
**boom** provides a set of utilities for returning HTTP errors. Each utility returns a `Boom` error response
|
||||
object (instance of `Error`) which includes the following properties:
|
||||
- `isBoom` - if `true`, indicates this is a `Boom` object instance.
|
||||
@@ -27,41 +70,6 @@ object (instance of `Error`) which includes the following properties:
|
||||
The `Boom` object also supports the following method:
|
||||
- `reformat()` - rebuilds `error.output` using the other object properties.
|
||||
|
||||
## Overview
|
||||
|
||||
- Helper methods
|
||||
- [`wrap(error, [statusCode], [message])`](#wraperror-statuscode-message)
|
||||
- [`create(statusCode, [message], [data])`](#createstatuscode-message-data)
|
||||
- HTTP 4xx Errors
|
||||
- 400: [`Boom.badRequest([message], [data])`](#boombadrequestmessage-data)
|
||||
- 401: [`Boom.unauthorized([message], [scheme], [attributes])`](#boomunauthorizedmessage-scheme-attributes)
|
||||
- 403: [`Boom.forbidden([message], [data])`](#boomforbiddenmessage-data)
|
||||
- 404: [`Boom.notFound([message], [data])`](#boomnotfoundmessage-data)
|
||||
- 405: [`Boom.methodNotAllowed([message], [data])`](#boommethodnotallowedmessage-data)
|
||||
- 406: [`Boom.notAcceptable([message], [data])`](#boomnotacceptablemessage-data)
|
||||
- 407: [`Boom.proxyAuthRequired([message], [data])`](#boomproxyauthrequiredmessage-data)
|
||||
- 408: [`Boom.clientTimeout([message], [data])`](#boomclienttimeoutmessage-data)
|
||||
- 409: [`Boom.conflict([message], [data])`](#boomconflictmessage-data)
|
||||
- 410: [`Boom.resourceGone([message], [data])`](#boomresourcegonemessage-data)
|
||||
- 411: [`Boom.lengthRequired([message], [data])`](#boomlengthrequiredmessage-data)
|
||||
- 412: [`Boom.preconditionFailed([message], [data])`](#boompreconditionfailedmessage-data)
|
||||
- 413: [`Boom.entityTooLarge([message], [data])`](#boomentitytoolargemessage-data)
|
||||
- 414: [`Boom.uriTooLong([message], [data])`](#boomuritoolongmessage-data)
|
||||
- 415: [`Boom.unsupportedMediaType([message], [data])`](#boomunsupportedmediatypemessage-data)
|
||||
- 416: [`Boom.rangeNotSatisfiable([message], [data])`](#boomrangenotsatisfiablemessage-data)
|
||||
- 417: [`Boom.expectationFailed([message], [data])`](#boomexpectationfailedmessage-data)
|
||||
- 422: [`Boom.badData([message], [data])`](#boombaddatamessage-data)
|
||||
- 428: [`Boom.preconditionRequired([message], [data])`](#boompreconditionrequiredmessage-data)
|
||||
- 429: [`Boom.tooManyRequests([message], [data])`](#boomtoomanyrequestsmessage-data)
|
||||
- HTTP 5xx Errors
|
||||
- 500: [`Boom.badImplementation([message], [data])`](#boombadimplementationmessage-data)
|
||||
- 501: [`Boom.notImplemented([message], [data])`](#boomnotimplementedmessage-data)
|
||||
- 502: [`Boom.badGateway([message], [data])`](#boombadgatewaymessage-data)
|
||||
- 503: [`Boom.serverTimeout([message], [data])`](#boomservertimeoutmessage-data)
|
||||
- 504: [`Boom.gatewayTimeout([message], [data])`](#boomgatewaytimeoutmessage-data)
|
||||
- [FAQ](#faq)
|
||||
|
||||
|
||||
## Helper Methods
|
||||
|
||||
### `wrap(error, [statusCode], [message])`
|
||||
@@ -118,8 +126,8 @@ Returns a 401 Unauthorized error where:
|
||||
- an authentication scheme name
|
||||
- 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"' as well as in the response payload under the `attributes` key.
|
||||
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. 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
|
||||
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.
|
||||
@@ -161,6 +169,23 @@ Generates the following response:
|
||||
}
|
||||
```
|
||||
|
||||
```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' });
|
||||
```
|
||||
@@ -184,6 +209,26 @@ Generates the following response:
|
||||
}
|
||||
```
|
||||
|
||||
### `Boom.paymentRequired([message], [data])`
|
||||
|
||||
Returns a 402 Payment Required error where:
|
||||
- `message` - optional message.
|
||||
- `data` - optional additional error data.
|
||||
|
||||
```js
|
||||
Boom.paymentRequired('bandwidth used');
|
||||
```
|
||||
|
||||
Generates the following response payload:
|
||||
|
||||
```json
|
||||
{
|
||||
"statusCode": 402,
|
||||
"error": "Payment Required",
|
||||
"message": "bandwidth used"
|
||||
}
|
||||
```
|
||||
|
||||
### `Boom.forbidden([message], [data])`
|
||||
|
||||
Returns a 403 Forbidden error where:
|
||||
@@ -224,11 +269,12 @@ Generates the following response payload:
|
||||
}
|
||||
```
|
||||
|
||||
### `Boom.methodNotAllowed([message], [data])`
|
||||
### `Boom.methodNotAllowed([message], [data], [allow])`
|
||||
|
||||
Returns a 405 Method Not Allowed error where:
|
||||
- `message` - optional message.
|
||||
- `data` - optional additional error data.
|
||||
- `allow` - optional string or array of strings (to be combined and separated by ', ') which is set to the 'Allow' header.
|
||||
|
||||
```js
|
||||
Boom.methodNotAllowed('that method is not allowed');
|
||||
@@ -482,6 +528,26 @@ Generates the following response payload:
|
||||
}
|
||||
```
|
||||
|
||||
### `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])`
|
||||
|
||||
Returns a 422 Unprocessable Entity error where:
|
||||
@@ -502,6 +568,26 @@ Generates the following response payload:
|
||||
}
|
||||
```
|
||||
|
||||
### `Boom.locked([message], [data])`
|
||||
|
||||
Returns a 423 Locked error where:
|
||||
- `message` - optional message.
|
||||
- `data` - optional additional error data.
|
||||
|
||||
```js
|
||||
Boom.locked('this resource has been locked');
|
||||
```
|
||||
|
||||
Generates the following response payload:
|
||||
|
||||
```json
|
||||
{
|
||||
"statusCode": 423,
|
||||
"error": "Locked",
|
||||
"message": "this resource has been locked"
|
||||
}
|
||||
```
|
||||
|
||||
### `Boom.preconditionRequired([message], [data])`
|
||||
|
||||
Returns a 428 Precondition Required error where:
|
||||
@@ -542,11 +628,31 @@ Generates the following response payload:
|
||||
}
|
||||
```
|
||||
|
||||
### `Boom.illegal([message], [data])`
|
||||
|
||||
Returns a 451 Unavailable For Legal Reasons error where:
|
||||
- `message` - optional message.
|
||||
- `data` - optional additional error data.
|
||||
|
||||
```js
|
||||
Boom.illegal('you are not permitted to view this resource for legal reasons');
|
||||
```
|
||||
|
||||
Generates the following response payload:
|
||||
|
||||
```json
|
||||
{
|
||||
"statusCode": 451,
|
||||
"error": "Unavailable For Legal Reasons",
|
||||
"message": "you are not permitted to view this resource for legal reasons"
|
||||
}
|
||||
```
|
||||
|
||||
## HTTP 5xx Errors
|
||||
|
||||
All 500 errors hide your message from the end user. Your message is recorded in the server log.
|
||||
|
||||
### `Boom.badImplementation([message], [data])`
|
||||
### `Boom.badImplementation([message], [data])` - (*alias: `internal`*)
|
||||
|
||||
Returns a 500 Internal Server Error error where:
|
||||
- `message` - optional message.
|
||||
@@ -606,14 +712,14 @@ Generates the following response payload:
|
||||
}
|
||||
```
|
||||
|
||||
### `Boom.serverTimeout([message], [data])`
|
||||
### `Boom.serverUnavailable([message], [data])`
|
||||
|
||||
Returns a 503 Service Unavailable error where:
|
||||
- `message` - optional message.
|
||||
- `data` - optional additional error data.
|
||||
|
||||
```js
|
||||
Boom.serverTimeout('unavailable');
|
||||
Boom.serverUnavailable('unavailable');
|
||||
```
|
||||
|
||||
Generates the following response payload:
|
||||
@@ -647,6 +753,8 @@ Generates the following response payload:
|
||||
|
||||
## F.A.Q.
|
||||
|
||||
###### How do I include extra information in my responses? `output.payload` is missing `data`, what gives?
|
||||
**Q** How do I include extra information in my responses? `output.payload` is missing `data`, what gives?
|
||||
|
||||
There is a reason the values passed back in the response payloads are pretty locked down. It's mostly for security and to not leak any important information back to the client. This means you will need to put in a little more effort to include extra information about your custom error. Check out the ["Error transformation"](https://github.com/hapijs/hapi/blob/master/API.md#error-transformation) section in the hapi documentation.
|
||||
**A** There is a reason the values passed back in the response payloads are pretty locked down. It's mostly for security and to not leak any important information back to the client. This means you will need to put in a little more effort to include extra information about your custom error. Check out the ["Error transformation"](https://github.com/hapijs/hapi/blob/master/API.md#error-transformation) section in the hapi documentation.
|
||||
|
||||
---
|
||||
BIN
Binary file not shown.
|
Before Width: | Height: | Size: 29 KiB |
+150
-35
@@ -1,16 +1,80 @@
|
||||
'use strict';
|
||||
|
||||
// Load modules
|
||||
|
||||
var Http = require('http');
|
||||
var Hoek = require('hoek');
|
||||
const Hoek = require('hoek');
|
||||
|
||||
|
||||
// Declare internals
|
||||
|
||||
var internals = {};
|
||||
const internals = {
|
||||
STATUS_CODES: Object.setPrototypeOf({
|
||||
'100': 'Continue',
|
||||
'101': 'Switching Protocols',
|
||||
'102': 'Processing',
|
||||
'200': 'OK',
|
||||
'201': 'Created',
|
||||
'202': 'Accepted',
|
||||
'203': 'Non-Authoritative Information',
|
||||
'204': 'No Content',
|
||||
'205': 'Reset Content',
|
||||
'206': 'Partial Content',
|
||||
'207': 'Multi-Status',
|
||||
'300': 'Multiple Choices',
|
||||
'301': 'Moved Permanently',
|
||||
'302': 'Moved Temporarily',
|
||||
'303': 'See Other',
|
||||
'304': 'Not Modified',
|
||||
'305': 'Use Proxy',
|
||||
'307': 'Temporary Redirect',
|
||||
'400': 'Bad Request',
|
||||
'401': 'Unauthorized',
|
||||
'402': 'Payment Required',
|
||||
'403': 'Forbidden',
|
||||
'404': 'Not Found',
|
||||
'405': 'Method Not Allowed',
|
||||
'406': 'Not Acceptable',
|
||||
'407': 'Proxy Authentication Required',
|
||||
'408': 'Request Time-out',
|
||||
'409': 'Conflict',
|
||||
'410': 'Gone',
|
||||
'411': 'Length Required',
|
||||
'412': 'Precondition Failed',
|
||||
'413': 'Request Entity Too Large',
|
||||
'414': 'Request-URI Too Large',
|
||||
'415': 'Unsupported Media Type',
|
||||
'416': 'Requested Range Not Satisfiable',
|
||||
'417': 'Expectation Failed',
|
||||
'418': 'I\'m a teapot',
|
||||
'422': 'Unprocessable Entity',
|
||||
'423': 'Locked',
|
||||
'424': 'Failed Dependency',
|
||||
'425': 'Unordered Collection',
|
||||
'426': 'Upgrade Required',
|
||||
'428': 'Precondition Required',
|
||||
'429': 'Too Many Requests',
|
||||
'431': 'Request Header Fields Too Large',
|
||||
'451': 'Unavailable For Legal Reasons',
|
||||
'500': 'Internal Server Error',
|
||||
'501': 'Not Implemented',
|
||||
'502': 'Bad Gateway',
|
||||
'503': 'Service Unavailable',
|
||||
'504': 'Gateway Time-out',
|
||||
'505': 'HTTP Version Not Supported',
|
||||
'506': 'Variant Also Negotiates',
|
||||
'507': 'Insufficient Storage',
|
||||
'509': 'Bandwidth Limit Exceeded',
|
||||
'510': 'Not Extended',
|
||||
'511': 'Network Authentication Required'
|
||||
}, null)
|
||||
};
|
||||
|
||||
|
||||
exports.wrap = function (error, statusCode, message) {
|
||||
|
||||
Hoek.assert(error instanceof Error, 'Cannot wrap non-Error object');
|
||||
Hoek.assert(!error.isBoom || (!statusCode && !message), 'Cannot provide statusCode or message with boom error');
|
||||
|
||||
return (error.isBoom ? error : internals.initialize(error, statusCode || 500, message));
|
||||
};
|
||||
|
||||
@@ -20,18 +84,27 @@ exports.create = function (statusCode, message, data) {
|
||||
return internals.create(statusCode, message, data, exports.create);
|
||||
};
|
||||
|
||||
|
||||
internals.create = function (statusCode, message, data, ctor) {
|
||||
|
||||
var error = new Error(message ? message : undefined); // Avoids settings null message
|
||||
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
|
||||
Error.captureStackTrace(error, ctor); // Filter the stack to our external API
|
||||
error.data = data || null;
|
||||
internals.initialize(error, statusCode);
|
||||
return error;
|
||||
};
|
||||
|
||||
|
||||
internals.initialize = function (error, statusCode, message) {
|
||||
|
||||
var numberCode = parseInt(statusCode, 10);
|
||||
const numberCode = parseInt(statusCode, 10);
|
||||
Hoek.assert(!isNaN(numberCode) && numberCode >= 400, 'First argument must be a number (400+):', statusCode);
|
||||
|
||||
error.isBoom = true;
|
||||
@@ -67,7 +140,7 @@ internals.initialize = function (error, statusCode, message) {
|
||||
internals.reformat = function () {
|
||||
|
||||
this.output.payload.statusCode = this.output.statusCode;
|
||||
this.output.payload.error = Http.STATUS_CODES[this.output.statusCode] || 'Unknown';
|
||||
this.output.payload.error = internals.STATUS_CODES[this.output.statusCode] || 'Unknown';
|
||||
|
||||
if (this.output.statusCode === 500) {
|
||||
this.output.payload.message = 'An internal server error occurred'; // Hide actual error from user
|
||||
@@ -88,15 +161,13 @@ exports.badRequest = function (message, data) {
|
||||
|
||||
exports.unauthorized = function (message, scheme, attributes) { // Or function (message, wwwAuthenticate[])
|
||||
|
||||
var err = internals.create(401, message, undefined, exports.unauthorized);
|
||||
const err = internals.create(401, message, undefined, exports.unauthorized);
|
||||
|
||||
if (!scheme) {
|
||||
return err;
|
||||
}
|
||||
|
||||
var wwwAuthenticate = '';
|
||||
var i = 0;
|
||||
var il = 0;
|
||||
let wwwAuthenticate = '';
|
||||
|
||||
if (typeof scheme === 'string') {
|
||||
|
||||
@@ -109,29 +180,36 @@ exports.unauthorized = function (message, scheme, attributes) { // Or f
|
||||
}
|
||||
|
||||
if (attributes) {
|
||||
var names = Object.keys(attributes);
|
||||
for (i = 0, il = names.length; i < il; ++i) {
|
||||
var name = names[i];
|
||||
if (i) {
|
||||
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 + ',';
|
||||
}
|
||||
|
||||
var 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 += ' ' + name + '="' + Hoek.escapeHeaderAttribute(value.toString()) + '"';
|
||||
err.output.payload.attributes[name] = value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (message) {
|
||||
if (attributes) {
|
||||
wwwAuthenticate += ',';
|
||||
wwwAuthenticate = wwwAuthenticate + ',';
|
||||
}
|
||||
wwwAuthenticate += ' error="' + Hoek.escapeHeaderAttribute(message) + '"';
|
||||
wwwAuthenticate = wwwAuthenticate + ' error="' + Hoek.escapeHeaderAttribute(message) + '"';
|
||||
err.output.payload.attributes.error = message;
|
||||
}
|
||||
else {
|
||||
@@ -142,13 +220,13 @@ exports.unauthorized = function (message, scheme, attributes) { // Or f
|
||||
|
||||
// function (message, wwwAuthenticate[])
|
||||
|
||||
var wwwArray = scheme;
|
||||
for (i = 0, il = wwwArray.length; i < il; ++i) {
|
||||
const wwwArray = scheme;
|
||||
for (let i = 0; i < wwwArray.length; ++i) {
|
||||
if (i) {
|
||||
wwwAuthenticate += ', ';
|
||||
wwwAuthenticate = wwwAuthenticate + ', ';
|
||||
}
|
||||
|
||||
wwwAuthenticate += wwwArray[i];
|
||||
wwwAuthenticate = wwwAuthenticate + wwwArray[i];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -158,6 +236,12 @@ exports.unauthorized = function (message, scheme, attributes) { // Or f
|
||||
};
|
||||
|
||||
|
||||
exports.paymentRequired = function (message, data) {
|
||||
|
||||
return internals.create(402, message, data, exports.paymentRequired);
|
||||
};
|
||||
|
||||
|
||||
exports.forbidden = function (message, data) {
|
||||
|
||||
return internals.create(403, message, data, exports.forbidden);
|
||||
@@ -170,9 +254,19 @@ exports.notFound = function (message, data) {
|
||||
};
|
||||
|
||||
|
||||
exports.methodNotAllowed = function (message, data) {
|
||||
exports.methodNotAllowed = function (message, data, allow) {
|
||||
|
||||
return internals.create(405, message, data, exports.methodNotAllowed);
|
||||
const err = internals.create(405, message, data, exports.methodNotAllowed);
|
||||
|
||||
if (typeof allow === 'string') {
|
||||
allow = [allow];
|
||||
}
|
||||
|
||||
if (Array.isArray(allow)) {
|
||||
err.output.headers.Allow = allow.join(', ');
|
||||
}
|
||||
|
||||
return err;
|
||||
};
|
||||
|
||||
|
||||
@@ -247,12 +341,25 @@ exports.expectationFailed = function (message, data) {
|
||||
return internals.create(417, message, data, exports.expectationFailed);
|
||||
};
|
||||
|
||||
|
||||
exports.teapot = function (message, data) {
|
||||
|
||||
return internals.create(418, message, data, exports.teapot);
|
||||
};
|
||||
|
||||
|
||||
exports.badData = function (message, data) {
|
||||
|
||||
return internals.create(422, message, data, exports.badData);
|
||||
};
|
||||
|
||||
|
||||
exports.locked = function (message, data) {
|
||||
|
||||
return internals.create(423, message, data, exports.locked);
|
||||
};
|
||||
|
||||
|
||||
exports.preconditionRequired = function (message, data) {
|
||||
|
||||
return internals.create(428, message, data, exports.preconditionRequired);
|
||||
@@ -265,6 +372,12 @@ exports.tooManyRequests = function (message, data) {
|
||||
};
|
||||
|
||||
|
||||
exports.illegal = function (message, data) {
|
||||
|
||||
return internals.create(451, message, data, exports.illegal);
|
||||
};
|
||||
|
||||
|
||||
// 5xx Server Errors
|
||||
|
||||
exports.internal = function (message, data, statusCode) {
|
||||
@@ -272,12 +385,14 @@ exports.internal = function (message, data, statusCode) {
|
||||
return internals.serverError(message, data, statusCode, exports.internal);
|
||||
};
|
||||
|
||||
|
||||
internals.serverError = function (message, data, statusCode, ctor) {
|
||||
|
||||
var error;
|
||||
let error;
|
||||
if (data instanceof Error) {
|
||||
error = exports.wrap(data, statusCode, message);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
error = internals.create(statusCode || 500, message, undefined, ctor);
|
||||
error.data = data;
|
||||
}
|
||||
@@ -298,9 +413,9 @@ exports.badGateway = function (message, data) {
|
||||
};
|
||||
|
||||
|
||||
exports.serverTimeout = function (message, data) {
|
||||
exports.serverUnavailable = function (message, data) {
|
||||
|
||||
return internals.serverError(message, data, 503, exports.serverTimeout);
|
||||
return internals.serverError(message, data, 503, exports.serverUnavailable);
|
||||
};
|
||||
|
||||
|
||||
@@ -312,7 +427,7 @@ exports.gatewayTimeout = function (message, data) {
|
||||
|
||||
exports.badImplementation = function (message, data) {
|
||||
|
||||
var err = internals.serverError(message, data, 500, exports.badImplementation);
|
||||
const err = internals.serverError(message, data, 500, exports.badImplementation);
|
||||
err.isDeveloperError = true;
|
||||
return err;
|
||||
};
|
||||
+26
-51
@@ -1,89 +1,64 @@
|
||||
{
|
||||
"_args": [
|
||||
[
|
||||
"boom@2.x.x",
|
||||
"c:\\users\\luis\\source\\repos\\AACharly\\node_modules\\hawk"
|
||||
"boom@4.3.1",
|
||||
"C:\\Users\\Luis\\source\\repos\\Bots\\AAMasters\\AACharly-Extraction-Bot"
|
||||
]
|
||||
],
|
||||
"_from": "boom@>=2.0.0-0 <3.0.0-0",
|
||||
"_id": "boom@2.10.1",
|
||||
"_inCache": true,
|
||||
"_from": "boom@4.3.1",
|
||||
"_id": "boom@4.3.1",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha1-T4owBctKfjiJ90kDD9JbluAdLjE=",
|
||||
"_location": "/boom",
|
||||
"_nodeVersion": "0.10.40",
|
||||
"_npmUser": {
|
||||
"email": "arbretz@gmail.com",
|
||||
"name": "arb"
|
||||
},
|
||||
"_npmVersion": "2.11.1",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "version",
|
||||
"registry": true,
|
||||
"raw": "boom@4.3.1",
|
||||
"name": "boom",
|
||||
"raw": "boom@2.x.x",
|
||||
"rawSpec": "2.x.x",
|
||||
"scope": null,
|
||||
"spec": ">=2.0.0-0 <3.0.0-0",
|
||||
"type": "range"
|
||||
"escapedName": "boom",
|
||||
"rawSpec": "4.3.1",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "4.3.1"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/cryptiles",
|
||||
"/hawk"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/boom/-/boom-2.10.1.tgz",
|
||||
"_shasum": "39c8918ceff5799f83f9492a848f625add0c766f",
|
||||
"_shrinkwrap": null,
|
||||
"_spec": "boom@2.x.x",
|
||||
"_where": "c:\\users\\luis\\source\\repos\\AACharly\\node_modules\\hawk",
|
||||
"_resolved": "https://registry.npmjs.org/boom/-/boom-4.3.1.tgz",
|
||||
"_spec": "4.3.1",
|
||||
"_where": "C:\\Users\\Luis\\source\\repos\\Bots\\AAMasters\\AACharly-Extraction-Bot",
|
||||
"bugs": {
|
||||
"url": "https://github.com/hapijs/boom/issues"
|
||||
},
|
||||
"dependencies": {
|
||||
"hoek": "2.x.x"
|
||||
"hoek": "4.x.x"
|
||||
},
|
||||
"description": "HTTP-friendly error objects",
|
||||
"devDependencies": {
|
||||
"code": "1.x.x",
|
||||
"lab": "7.x.x"
|
||||
},
|
||||
"directories": {},
|
||||
"dist": {
|
||||
"shasum": "39c8918ceff5799f83f9492a848f625add0c766f",
|
||||
"tarball": "https://registry.npmjs.org/boom/-/boom-2.10.1.tgz"
|
||||
"code": "4.x.x",
|
||||
"lab": "13.x.x",
|
||||
"markdown-toc": "0.12.x"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=0.10.40"
|
||||
"node": ">=4.0.0"
|
||||
},
|
||||
"gitHead": "ff1a662a86b39426cdd18f4441b112d307a34a6f",
|
||||
"homepage": "https://github.com/hapijs/boom#readme",
|
||||
"installable": true,
|
||||
"keywords": [
|
||||
"error",
|
||||
"http"
|
||||
],
|
||||
"license": "BSD-3-Clause",
|
||||
"main": "lib/index.js",
|
||||
"maintainers": [
|
||||
{
|
||||
"name": "hueniverse",
|
||||
"email": "eran@hueniverse.com"
|
||||
},
|
||||
{
|
||||
"name": "wyatt",
|
||||
"email": "wpreul@gmail.com"
|
||||
},
|
||||
{
|
||||
"name": "arb",
|
||||
"email": "arbretz@gmail.com"
|
||||
}
|
||||
],
|
||||
"name": "boom",
|
||||
"optionalDependencies": {},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/hapijs/boom.git"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "lab -a code -t 100 -L",
|
||||
"test-cov-html": "lab -a code -r html -o coverage.html -L"
|
||||
"test": "lab -a code -t 100 -L -v",
|
||||
"test-cov-html": "lab -a code -r html -o coverage.html -L",
|
||||
"toc": "node generate-toc.js",
|
||||
"version": "npm run toc && git add README.md"
|
||||
},
|
||||
"version": "2.10.1"
|
||||
"version": "4.3.1"
|
||||
}
|
||||
-654
@@ -1,654 +0,0 @@
|
||||
// Load modules
|
||||
|
||||
var Code = require('code');
|
||||
var Boom = require('../lib');
|
||||
var Lab = require('lab');
|
||||
|
||||
|
||||
// Declare internals
|
||||
|
||||
var internals = {};
|
||||
|
||||
|
||||
// Test shortcuts
|
||||
|
||||
var lab = exports.lab = Lab.script();
|
||||
var describe = lab.describe;
|
||||
var it = lab.it;
|
||||
var expect = Code.expect;
|
||||
|
||||
|
||||
it('returns the same object when already boom', function (done) {
|
||||
|
||||
var error = Boom.badRequest();
|
||||
var wrapped = Boom.wrap(error);
|
||||
expect(error).to.equal(wrapped);
|
||||
done();
|
||||
});
|
||||
|
||||
it('returns an error with info when constructed using another error', function (done) {
|
||||
|
||||
var error = new Error('ka-boom');
|
||||
error.xyz = 123;
|
||||
var err = Boom.wrap(error);
|
||||
expect(err.xyz).to.equal(123);
|
||||
expect(err.message).to.equal('ka-boom');
|
||||
expect(err.output).to.deep.equal({
|
||||
statusCode: 500,
|
||||
payload: {
|
||||
statusCode: 500,
|
||||
error: 'Internal Server Error',
|
||||
message: 'An internal server error occurred'
|
||||
},
|
||||
headers: {}
|
||||
});
|
||||
expect(err.data).to.equal(null);
|
||||
done();
|
||||
});
|
||||
|
||||
it('does not override data when constructed using another error', function (done) {
|
||||
|
||||
var error = new Error('ka-boom');
|
||||
error.data = { useful: 'data' };
|
||||
var err = Boom.wrap(error);
|
||||
expect(err.data).to.equal(error.data);
|
||||
done();
|
||||
});
|
||||
|
||||
it('sets new message when none exists', function (done) {
|
||||
|
||||
var error = new Error();
|
||||
var wrapped = Boom.wrap(error, 400, 'something bad');
|
||||
expect(wrapped.message).to.equal('something bad');
|
||||
done();
|
||||
});
|
||||
|
||||
it('throws when statusCode is not a number', function (done) {
|
||||
|
||||
expect(function () {
|
||||
|
||||
Boom.create('x');
|
||||
}).to.throw('First argument must be a number (400+): x');
|
||||
done();
|
||||
});
|
||||
|
||||
it('will cast a number-string to an integer', function (done) {
|
||||
|
||||
var codes = [
|
||||
{ input: '404', result: 404 },
|
||||
{ input: '404.1', result: 404 },
|
||||
{ input: 400, result: 400 },
|
||||
{ input: 400.123, result: 400 }];
|
||||
for (var i = 0, il = codes.length; i < il; ++i) {
|
||||
var code = codes[i];
|
||||
var err = Boom.create(code.input);
|
||||
expect(err.output.statusCode).to.equal(code.result);
|
||||
}
|
||||
|
||||
done();
|
||||
});
|
||||
|
||||
it('throws when statusCode is not finite', function (done) {
|
||||
|
||||
expect(function () {
|
||||
|
||||
Boom.create(1 / 0);
|
||||
}).to.throw('First argument must be a number (400+): null');
|
||||
done();
|
||||
});
|
||||
|
||||
it('sets error code to unknown', function (done) {
|
||||
|
||||
var err = Boom.create(999);
|
||||
expect(err.output.payload.error).to.equal('Unknown');
|
||||
done();
|
||||
});
|
||||
|
||||
describe('create()', function () {
|
||||
|
||||
it('does not sets null message', function (done) {
|
||||
|
||||
var error = Boom.unauthorized(null);
|
||||
expect(error.output.payload.message).to.not.exist();
|
||||
expect(error.isServer).to.be.false();
|
||||
done();
|
||||
});
|
||||
|
||||
it('sets message and data', function (done) {
|
||||
|
||||
var error = Boom.badRequest('Missing data', { type: 'user' });
|
||||
expect(error.data.type).to.equal('user');
|
||||
expect(error.output.payload.message).to.equal('Missing data');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
describe('isBoom()', function () {
|
||||
|
||||
it('returns true for Boom object', function (done) {
|
||||
|
||||
expect(Boom.badRequest().isBoom).to.equal(true);
|
||||
done();
|
||||
});
|
||||
|
||||
it('returns false for Error object', function (done) {
|
||||
|
||||
expect((new Error()).isBoom).to.not.exist();
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
describe('badRequest()', function () {
|
||||
|
||||
it('returns a 400 error statusCode', function (done) {
|
||||
|
||||
var error = Boom.badRequest();
|
||||
|
||||
expect(error.output.statusCode).to.equal(400);
|
||||
expect(error.isServer).to.be.false();
|
||||
done();
|
||||
});
|
||||
|
||||
it('sets the message with the passed in message', function (done) {
|
||||
|
||||
expect(Boom.badRequest('my message').message).to.equal('my message');
|
||||
done();
|
||||
});
|
||||
|
||||
it('sets the message to HTTP status if none provided', function (done) {
|
||||
|
||||
expect(Boom.badRequest().message).to.equal('Bad Request');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
describe('unauthorized()', function () {
|
||||
|
||||
it('returns a 401 error statusCode', function (done) {
|
||||
|
||||
var err = Boom.unauthorized();
|
||||
expect(err.output.statusCode).to.equal(401);
|
||||
expect(err.output.headers).to.deep.equal({});
|
||||
done();
|
||||
});
|
||||
|
||||
it('sets the message with the passed in message', function (done) {
|
||||
|
||||
expect(Boom.unauthorized('my message').message).to.equal('my message');
|
||||
done();
|
||||
});
|
||||
|
||||
it('returns a WWW-Authenticate header when passed a scheme', function (done) {
|
||||
|
||||
var err = Boom.unauthorized('boom', 'Test');
|
||||
expect(err.output.statusCode).to.equal(401);
|
||||
expect(err.output.headers['WWW-Authenticate']).to.equal('Test error="boom"');
|
||||
done();
|
||||
});
|
||||
|
||||
it('returns a WWW-Authenticate header set to the schema array value', function (done) {
|
||||
|
||||
var err = Boom.unauthorized(null, ['Test','one','two']);
|
||||
expect(err.output.statusCode).to.equal(401);
|
||||
expect(err.output.headers['WWW-Authenticate']).to.equal('Test, one, two');
|
||||
done();
|
||||
});
|
||||
|
||||
it('returns a WWW-Authenticate header when passed a scheme and attributes', function (done) {
|
||||
|
||||
var err = Boom.unauthorized('boom', 'Test', { a: 1, b: 'something', c: null, d: 0 });
|
||||
expect(err.output.statusCode).to.equal(401);
|
||||
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();
|
||||
});
|
||||
|
||||
it('returns a WWW-Authenticate header when passed attributes, missing error', function (done) {
|
||||
|
||||
var err = Boom.unauthorized(null, 'Test', { a: 1, b: 'something', c: null, d: 0 });
|
||||
expect(err.output.statusCode).to.equal(401);
|
||||
expect(err.output.headers['WWW-Authenticate']).to.equal('Test a="1", b="something", c="", d="0"');
|
||||
expect(err.isMissing).to.equal(true);
|
||||
done();
|
||||
});
|
||||
|
||||
it('sets the isMissing flag when error message is empty', function (done) {
|
||||
|
||||
var err = Boom.unauthorized('', 'Basic');
|
||||
expect(err.isMissing).to.equal(true);
|
||||
done();
|
||||
});
|
||||
|
||||
it('does not set the isMissing flag when error message is not empty', function (done) {
|
||||
|
||||
var err = Boom.unauthorized('message', 'Basic');
|
||||
expect(err.isMissing).to.equal(undefined);
|
||||
done();
|
||||
});
|
||||
|
||||
it('sets a WWW-Authenticate when passed as an array', function (done) {
|
||||
|
||||
var err = Boom.unauthorized('message', ['Basic', 'Example e="1"', 'Another x="3", y="4"']);
|
||||
expect(err.output.headers['WWW-Authenticate']).to.equal('Basic, Example e="1", Another x="3", y="4"');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
describe('methodNotAllowed()', function () {
|
||||
|
||||
it('returns a 405 error statusCode', function (done) {
|
||||
|
||||
expect(Boom.methodNotAllowed().output.statusCode).to.equal(405);
|
||||
done();
|
||||
});
|
||||
|
||||
it('sets the message with the passed in message', function (done) {
|
||||
|
||||
expect(Boom.methodNotAllowed('my message').message).to.equal('my message');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
describe('notAcceptable()', function () {
|
||||
|
||||
it('returns a 406 error statusCode', function (done) {
|
||||
|
||||
expect(Boom.notAcceptable().output.statusCode).to.equal(406);
|
||||
done();
|
||||
});
|
||||
|
||||
it('sets the message with the passed in message', function (done) {
|
||||
|
||||
expect(Boom.notAcceptable('my message').message).to.equal('my message');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
describe('proxyAuthRequired()', function () {
|
||||
|
||||
it('returns a 407 error statusCode', function (done) {
|
||||
|
||||
expect(Boom.proxyAuthRequired().output.statusCode).to.equal(407);
|
||||
done();
|
||||
});
|
||||
|
||||
it('sets the message with the passed in message', function (done) {
|
||||
|
||||
expect(Boom.proxyAuthRequired('my message').message).to.equal('my message');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
describe('clientTimeout()', function () {
|
||||
|
||||
it('returns a 408 error statusCode', function (done) {
|
||||
|
||||
expect(Boom.clientTimeout().output.statusCode).to.equal(408);
|
||||
done();
|
||||
});
|
||||
|
||||
it('sets the message with the passed in message', function (done) {
|
||||
|
||||
expect(Boom.clientTimeout('my message').message).to.equal('my message');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
describe('conflict()', function () {
|
||||
|
||||
it('returns a 409 error statusCode', function (done) {
|
||||
|
||||
expect(Boom.conflict().output.statusCode).to.equal(409);
|
||||
done();
|
||||
});
|
||||
|
||||
it('sets the message with the passed in message', function (done) {
|
||||
|
||||
expect(Boom.conflict('my message').message).to.equal('my message');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
describe('resourceGone()', function () {
|
||||
|
||||
it('returns a 410 error statusCode', function (done) {
|
||||
|
||||
expect(Boom.resourceGone().output.statusCode).to.equal(410);
|
||||
done();
|
||||
});
|
||||
|
||||
it('sets the message with the passed in message', function (done) {
|
||||
|
||||
expect(Boom.resourceGone('my message').message).to.equal('my message');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
describe('lengthRequired()', function () {
|
||||
|
||||
it('returns a 411 error statusCode', function (done) {
|
||||
|
||||
expect(Boom.lengthRequired().output.statusCode).to.equal(411);
|
||||
done();
|
||||
});
|
||||
|
||||
it('sets the message with the passed in message', function (done) {
|
||||
|
||||
expect(Boom.lengthRequired('my message').message).to.equal('my message');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
describe('preconditionFailed()', function () {
|
||||
|
||||
it('returns a 412 error statusCode', function (done) {
|
||||
|
||||
expect(Boom.preconditionFailed().output.statusCode).to.equal(412);
|
||||
done();
|
||||
});
|
||||
|
||||
it('sets the message with the passed in message', function (done) {
|
||||
|
||||
expect(Boom.preconditionFailed('my message').message).to.equal('my message');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
describe('entityTooLarge()', function () {
|
||||
|
||||
it('returns a 413 error statusCode', function (done) {
|
||||
|
||||
expect(Boom.entityTooLarge().output.statusCode).to.equal(413);
|
||||
done();
|
||||
});
|
||||
|
||||
it('sets the message with the passed in message', function (done) {
|
||||
|
||||
expect(Boom.entityTooLarge('my message').message).to.equal('my message');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
describe('uriTooLong()', function () {
|
||||
|
||||
it('returns a 414 error statusCode', function (done) {
|
||||
|
||||
expect(Boom.uriTooLong().output.statusCode).to.equal(414);
|
||||
done();
|
||||
});
|
||||
|
||||
it('sets the message with the passed in message', function (done) {
|
||||
|
||||
expect(Boom.uriTooLong('my message').message).to.equal('my message');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
describe('unsupportedMediaType()', function () {
|
||||
|
||||
it('returns a 415 error statusCode', function (done) {
|
||||
|
||||
expect(Boom.unsupportedMediaType().output.statusCode).to.equal(415);
|
||||
done();
|
||||
});
|
||||
|
||||
it('sets the message with the passed in message', function (done) {
|
||||
|
||||
expect(Boom.unsupportedMediaType('my message').message).to.equal('my message');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
describe('rangeNotSatisfiable()', function () {
|
||||
|
||||
it('returns a 416 error statusCode', function (done) {
|
||||
|
||||
expect(Boom.rangeNotSatisfiable().output.statusCode).to.equal(416);
|
||||
done();
|
||||
});
|
||||
|
||||
it('sets the message with the passed in message', function (done) {
|
||||
|
||||
expect(Boom.rangeNotSatisfiable('my message').message).to.equal('my message');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
describe('expectationFailed()', function () {
|
||||
|
||||
it('returns a 417 error statusCode', function (done) {
|
||||
|
||||
expect(Boom.expectationFailed().output.statusCode).to.equal(417);
|
||||
done();
|
||||
});
|
||||
|
||||
it('sets the message with the passed in message', function (done) {
|
||||
|
||||
expect(Boom.expectationFailed('my message').message).to.equal('my message');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
describe('badData()', function () {
|
||||
|
||||
it('returns a 422 error statusCode', function (done) {
|
||||
|
||||
expect(Boom.badData().output.statusCode).to.equal(422);
|
||||
done();
|
||||
});
|
||||
|
||||
it('sets the message with the passed in message', function (done) {
|
||||
|
||||
expect(Boom.badData('my message').message).to.equal('my message');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
describe('preconditionRequired()', function () {
|
||||
|
||||
it('returns a 428 error statusCode', function (done) {
|
||||
|
||||
expect(Boom.preconditionRequired().output.statusCode).to.equal(428);
|
||||
done();
|
||||
});
|
||||
|
||||
it('sets the message with the passed in message', function (done) {
|
||||
|
||||
expect(Boom.preconditionRequired('my message').message).to.equal('my message');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
describe('tooManyRequests()', function () {
|
||||
|
||||
it('returns a 429 error statusCode', function (done) {
|
||||
|
||||
expect(Boom.tooManyRequests().output.statusCode).to.equal(429);
|
||||
done();
|
||||
});
|
||||
|
||||
it('sets the message with the passed-in message', function (done) {
|
||||
|
||||
expect(Boom.tooManyRequests('my message').message).to.equal('my message');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
describe('serverTimeout()', function () {
|
||||
|
||||
it('returns a 503 error statusCode', function (done) {
|
||||
|
||||
expect(Boom.serverTimeout().output.statusCode).to.equal(503);
|
||||
done();
|
||||
});
|
||||
|
||||
it('sets the message with the passed in message', function (done) {
|
||||
|
||||
expect(Boom.serverTimeout('my message').message).to.equal('my message');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
describe('forbidden()', function () {
|
||||
|
||||
it('returns a 403 error statusCode', function (done) {
|
||||
|
||||
expect(Boom.forbidden().output.statusCode).to.equal(403);
|
||||
done();
|
||||
});
|
||||
|
||||
it('sets the message with the passed in message', function (done) {
|
||||
|
||||
expect(Boom.forbidden('my message').message).to.equal('my message');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
describe('notFound()', function () {
|
||||
|
||||
it('returns a 404 error statusCode', function (done) {
|
||||
|
||||
expect(Boom.notFound().output.statusCode).to.equal(404);
|
||||
done();
|
||||
});
|
||||
|
||||
it('sets the message with the passed in message', function (done) {
|
||||
|
||||
expect(Boom.notFound('my message').message).to.equal('my message');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
describe('internal()', function () {
|
||||
|
||||
it('returns a 500 error statusCode', function (done) {
|
||||
|
||||
expect(Boom.internal().output.statusCode).to.equal(500);
|
||||
done();
|
||||
});
|
||||
|
||||
it('sets the message with the passed in message', function (done) {
|
||||
|
||||
var err = Boom.internal('my message');
|
||||
expect(err.message).to.equal('my message');
|
||||
expect(err.isServer).to.true();
|
||||
expect(err.output.payload.message).to.equal('An internal server error occurred');
|
||||
done();
|
||||
});
|
||||
|
||||
it('passes data on the callback if its passed in', function (done) {
|
||||
|
||||
expect(Boom.internal('my message', { my: 'data' }).data.my).to.equal('data');
|
||||
done();
|
||||
});
|
||||
|
||||
it('returns an error with composite message', function (done) {
|
||||
|
||||
try {
|
||||
JSON.parse('{');
|
||||
}
|
||||
catch (err) {
|
||||
var boom = Boom.internal('Someting bad', err);
|
||||
expect(boom.message).to.equal('Someting bad: Unexpected end of input');
|
||||
expect(boom.isServer).to.be.true();
|
||||
done();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe('notImplemented()', function () {
|
||||
|
||||
it('returns a 501 error statusCode', function (done) {
|
||||
|
||||
expect(Boom.notImplemented().output.statusCode).to.equal(501);
|
||||
done();
|
||||
});
|
||||
|
||||
it('sets the message with the passed in message', function (done) {
|
||||
|
||||
expect(Boom.notImplemented('my message').message).to.equal('my message');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
describe('badGateway()', function () {
|
||||
|
||||
it('returns a 502 error statusCode', function (done) {
|
||||
|
||||
expect(Boom.badGateway().output.statusCode).to.equal(502);
|
||||
done();
|
||||
});
|
||||
|
||||
it('sets the message with the passed in message', function (done) {
|
||||
|
||||
expect(Boom.badGateway('my message').message).to.equal('my message');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
describe('gatewayTimeout()', function () {
|
||||
|
||||
it('returns a 504 error statusCode', function (done) {
|
||||
|
||||
expect(Boom.gatewayTimeout().output.statusCode).to.equal(504);
|
||||
done();
|
||||
});
|
||||
|
||||
it('sets the message with the passed in message', function (done) {
|
||||
|
||||
expect(Boom.gatewayTimeout('my message').message).to.equal('my message');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
describe('badImplementation()', function () {
|
||||
|
||||
it('returns a 500 error statusCode', function (done) {
|
||||
|
||||
var err = Boom.badImplementation();
|
||||
expect(err.output.statusCode).to.equal(500);
|
||||
expect(err.isDeveloperError).to.equal(true);
|
||||
expect(err.isServer).to.be.true();
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
describe('stack trace', function () {
|
||||
|
||||
it('should omit lib', function (done) {
|
||||
|
||||
['badRequest', 'unauthorized', 'forbidden', 'notFound', 'methodNotAllowed',
|
||||
'notAcceptable', 'proxyAuthRequired', 'clientTimeout', 'conflict',
|
||||
'resourceGone', 'lengthRequired', 'preconditionFailed', 'entityTooLarge',
|
||||
'uriTooLong', 'unsupportedMediaType', 'rangeNotSatisfiable', 'expectationFailed',
|
||||
'badData', 'preconditionRequired', 'tooManyRequests',
|
||||
|
||||
// 500s
|
||||
'internal', 'notImplemented', 'badGateway', 'serverTimeout', 'gatewayTimeout',
|
||||
'badImplementation'
|
||||
].forEach(function (name) {
|
||||
|
||||
var err = Boom[name]();
|
||||
expect(err.stack).to.not.match(/\/lib\/index\.js/);
|
||||
});
|
||||
|
||||
done();
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user