boom
Advanced tools
Comparing version 3.0.0 to 3.1.0
@@ -5,3 +5,2 @@ 'use strict'; | ||
const Http = require('http'); | ||
const Hoek = require('hoek'); | ||
@@ -12,3 +11,64 @@ | ||
const internals = {}; | ||
const internals = { | ||
STATUS_CODES: { | ||
__proto__: null, | ||
'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' | ||
} | ||
}; | ||
@@ -76,3 +136,3 @@ exports.wrap = function (error, statusCode, message) { | ||
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'; | ||
@@ -274,2 +334,8 @@ if (this.output.statusCode === 500) { | ||
exports.illegal = function (message, data) { | ||
return internals.create(451, message, data, exports.illegal); | ||
}; | ||
// 5xx Server Errors | ||
@@ -276,0 +342,0 @@ |
{ | ||
"name": "boom", | ||
"description": "HTTP-friendly error objects", | ||
"version": "3.0.0", | ||
"version": "3.1.0", | ||
"repository": "git://github.com/hapijs/boom", | ||
@@ -19,9 +19,12 @@ "main": "lib/index.js", | ||
"code": "2.x.x", | ||
"lab": "7.x.x" | ||
"lab": "7.x.x", | ||
"markdown-toc": "0.11.x" | ||
}, | ||
"scripts": { | ||
"test": "lab -a code -t 100 -L", | ||
"test-cov-html": "lab -a code -r html -o coverage.html -L" | ||
"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" | ||
}, | ||
"license": "BSD-3-Clause" | ||
} |
102
README.md
@@ -10,2 +10,42 @@ ![boom Logo](https://raw.github.com/hapijs/boom/master/images/boom.png) | ||
<!-- 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.forbidden([message], [data])`](#boomforbiddenmessage-data) | ||
- [`Boom.notFound([message], [data])`](#boomnotfoundmessage-data) | ||
- [`Boom.methodNotAllowed([message], [data])`](#boommethodnotallowedmessage-data) | ||
- [`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.badData([message], [data])`](#boombaddatamessage-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])`](#boombadimplementationmessage-data) | ||
- [`Boom.notImplemented([message], [data])`](#boomnotimplementedmessage-data) | ||
- [`Boom.badGateway([message], [data])`](#boombadgatewaymessage-data) | ||
- [`Boom.serverTimeout([message], [data])`](#boomservertimeoutmessage-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 | ||
@@ -31,37 +71,3 @@ object (instance of `Error`) which includes the following 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 | ||
@@ -123,3 +129,3 @@ | ||
- `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 | ||
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. | ||
@@ -548,2 +554,22 @@ `null` and `undefined` will be replaced with an empty string. If `attributes` is set, `message` will be used as | ||
### `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 | ||
@@ -654,4 +680,6 @@ | ||
###### 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. | ||
--- |
@@ -497,2 +497,19 @@ 'use strict'; | ||
describe('illegal()', () => { | ||
it('returns a 451 error statusCode', (done) => { | ||
expect(Boom.illegal().output.statusCode).to.equal(451); | ||
done(); | ||
}); | ||
it('sets the message with the passed-in message', (done) => { | ||
expect(Boom.illegal('my message').message).to.equal('my message'); | ||
done(); | ||
}); | ||
}); | ||
describe('serverTimeout()', () => { | ||
@@ -499,0 +516,0 @@ |
Sorry, the diff of this file is not supported yet
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
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
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
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
77012
10
738
681
0
3
2