pax_global_header00006660000000000000000000000064143717513450014524gustar00rootroot0000000000000052 comment=01a4996dc6e62949aa7a98ca75b2d0dcd8a4a0a8 boom-10.0.1/000077500000000000000000000000001437175134500125375ustar00rootroot00000000000000boom-10.0.1/.github/000077500000000000000000000000001437175134500140775ustar00rootroot00000000000000boom-10.0.1/.github/workflows/000077500000000000000000000000001437175134500161345ustar00rootroot00000000000000boom-10.0.1/.github/workflows/ci-module.yml000066400000000000000000000003141437175134500205330ustar00rootroot00000000000000name: ci on: push: branches: - master pull_request: workflow_dispatch: jobs: test: uses: hapijs/.github/.github/workflows/ci-module.yml@master with: min-node-version: 14 boom-10.0.1/.gitignore000066400000000000000000000001541437175134500145270ustar00rootroot00000000000000**/node_modules **/package-lock.json coverage.* **/.DS_Store **/._* **/*.pem **/.vs **/.vscode **/.idea boom-10.0.1/API.md000077500000000000000000000447601437175134500135100ustar00rootroot00000000000000 **boom** provides a set of utilities for returning HTTP errors. Each utility returns a `Boom` error response object which includes the following properties: - `isBoom` - if `true`, indicates this is a `Boom` object instance. Note that this boolean should only be used if the error is an instance of `Error`. If it is not certain, use `Boom.isBoom()` instead. - `isServer` - convenience bool indicating status code >= 500. - `message` - the error message. - `typeof` - the constructor used to create the error (e.g. `Boom.badRequest`). - `output` - the formatted response. Can be directly manipulated after object construction to return a custom error response. Allowed root keys: - `statusCode` - the HTTP status code (typically 4xx or 5xx). - `headers` - an object containing any HTTP headers where each key is a header name and value is the header content. - `payload` - the formatted object used as the response payload (stringified). Can be directly manipulated but any changes will be lost if `reformat()` is called. Any content allowed and by default includes the following content: - `statusCode` - the HTTP status code, derived from `error.output.statusCode`. - `error` - the HTTP status message (e.g. 'Bad Request', 'Internal Server Error') derived from `statusCode`. - `message` - the error message derived from `error.message`. - inherited `Error` properties. The `Boom` object also supports the following method: #### `reformat(debug)` Rebuilds `error.output` using the other object properties where: - `debug` - a Boolean that, when `true`, causes Internal Server Error messages to be left in tact. Defaults to `false`, meaning that Internal Server Error messages are redacted. Note that `Boom` object will return `true` when used with `instanceof Boom`, but do not use the `Boom` prototype (they are either plain `Error` or the error prototype passed in). This means `Boom` objects should only be tested using `instanceof Boom` or `Boom.isBoom()` but not by looking at the prototype or contructor information. This limitation is to avoid manipulating the prototype chain which is very slow. #### Helper Methods ##### `new Boom.Boom(message, [options])` Creates a new `Boom` object using the provided `message` and then calling [`boomify()`](#boomifyerr-options) to decorate the error with the `Boom` properties, where: - `message` - the error message. If `message` is an error, it is the same as calling [`boomify()`](#boomifyerr-options) directly. - `options` - and optional object where: - `statusCode` - the HTTP status code. Defaults to `500` if no status code is already set. - `data` - additional error information (assigned to `error.data`). - `decorate` - an option with extra properties to set on the error object. - `ctor` - constructor reference used to crop the exception call stack output. - if `message` is an error object, also supports the other [`boomify()`](#boomifyerr-options) options. ##### `boomify(err, [options])` Decorates an error with the `Boom` properties where: - `err` - the `Error` object to decorate. - `options` - optional object with the following optional settings: - `statusCode` - the HTTP status code. Defaults to `500` if no status code is already set and `err` is not a `Boom` object. - `message` - error message string. If the error already has a message, the provided `message` is added as a prefix. Defaults to no message. - `decorate` - an option with extra properties to set on the error object. - `override` - if `false`, the `err` provided is a `Boom` object, and a `statusCode` or `message` are provided, the values are ignored. Defaults to `true` (apply the provided `statusCode` and `message` options to the error regardless of its type, `Error` or `Boom` object). ```js var error = new Error('Unexpected input'); Boom.boomify(error, { statusCode: 400 }); ``` ##### `isBoom(err, [statusCode])` Identifies whether an error is a `Boom` object. Same as calling `instanceof Boom.Boom`. - `err` - Error object. - `statusCode` - optional status code. ```js Boom.isBoom(Boom.badRequest()); // true Boom.isBoom(Boom.badRequest(), 400); // true ``` #### HTTP 4xx Errors ##### `Boom.badRequest([message], [data])` Returns a 400 Bad Request error where: - `message` - optional message. - `data` - optional additional error data. ```js Boom.badRequest('invalid query'); ``` Generates the following response payload: ```json { "statusCode": 400, "error": "Bad Request", "message": "invalid query" } ``` ##### `Boom.unauthorized([message], [scheme], [attributes])` Returns a 401 Unauthorized error where: - `message` - optional message. - `scheme` can be one of the following: - 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 `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. If either `scheme` or `attributes` are set, the resultant `Boom` object will have the 'WWW-Authenticate' header set for the response. ```js Boom.unauthorized('invalid password'); ``` Generates the following response: ```json "payload": { "statusCode": 401, "error": "Unauthorized", "message": "invalid password" }, "headers": {} ``` ```js Boom.unauthorized('invalid password', 'sample'); ``` Generates the following response: ```json "payload": { "statusCode": 401, "error": "Unauthorized", "message": "invalid password", "attributes": { "error": "invalid password" } }, "headers": { "WWW-Authenticate": "sample error=\"invalid password\"" } ``` ```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' }); ``` Generates the following response: ```json "payload": { "statusCode": 401, "error": "Unauthorized", "message": "invalid password", "attributes": { "error": "invalid password", "ttl": 0, "cache": "", "foo": "bar" } }, "headers": { "WWW-Authenticate": "sample ttl=\"0\", cache=\"\", foo=\"bar\", error=\"invalid password\"" } ``` ##### `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: - `message` - optional message. - `data` - optional additional error data. ```js Boom.forbidden('try again some time'); ``` Generates the following response payload: ```json { "statusCode": 403, "error": "Forbidden", "message": "try again some time" } ``` ##### `Boom.notFound([message], [data])` Returns a 404 Not Found error where: - `message` - optional message. - `data` - optional additional error data. ```js Boom.notFound('missing'); ``` Generates the following response payload: ```json { "statusCode": 404, "error": "Not Found", "message": "missing" } ``` ##### `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'); ``` Generates the following response payload: ```json { "statusCode": 405, "error": "Method Not Allowed", "message": "that method is not allowed" } ``` ##### `Boom.notAcceptable([message], [data])` Returns a 406 Not Acceptable error where: - `message` - optional message. - `data` - optional additional error data. ```js Boom.notAcceptable('unacceptable'); ``` Generates the following response payload: ```json { "statusCode": 406, "error": "Not Acceptable", "message": "unacceptable" } ``` ##### `Boom.proxyAuthRequired([message], [data])` Returns a 407 Proxy Authentication Required error where: - `message` - optional message. - `data` - optional additional error data. ```js Boom.proxyAuthRequired('auth missing'); ``` Generates the following response payload: ```json { "statusCode": 407, "error": "Proxy Authentication Required", "message": "auth missing" } ``` ##### `Boom.clientTimeout([message], [data])` Returns a 408 Request Time-out error where: - `message` - optional message. - `data` - optional additional error data. ```js Boom.clientTimeout('timed out'); ``` Generates the following response payload: ```json { "statusCode": 408, "error": "Request Time-out", "message": "timed out" } ``` ##### `Boom.conflict([message], [data])` Returns a 409 Conflict error where: - `message` - optional message. - `data` - optional additional error data. ```js Boom.conflict('there was a conflict'); ``` Generates the following response payload: ```json { "statusCode": 409, "error": "Conflict", "message": "there was a conflict" } ``` ##### `Boom.resourceGone([message], [data])` Returns a 410 Gone error where: - `message` - optional message. - `data` - optional additional error data. ```js Boom.resourceGone('it is gone'); ``` Generates the following response payload: ```json { "statusCode": 410, "error": "Gone", "message": "it is gone" } ``` ##### `Boom.lengthRequired([message], [data])` Returns a 411 Length Required error where: - `message` - optional message. - `data` - optional additional error data. ```js Boom.lengthRequired('length needed'); ``` Generates the following response payload: ```json { "statusCode": 411, "error": "Length Required", "message": "length needed" } ``` ##### `Boom.preconditionFailed([message], [data])` Returns a 412 Precondition Failed error where: - `message` - optional message. - `data` - optional additional error data. ```js Boom.preconditionFailed(); ``` Generates the following response payload: ```json { "statusCode": 412, "error": "Precondition Failed" } ``` ##### `Boom.entityTooLarge([message], [data])` Returns a 413 Request Entity Too Large error where: - `message` - optional message. - `data` - optional additional error data. ```js Boom.entityTooLarge('too big'); ``` Generates the following response payload: ```json { "statusCode": 413, "error": "Request Entity Too Large", "message": "too big" } ``` ##### `Boom.uriTooLong([message], [data])` Returns a 414 Request-URI Too Large error where: - `message` - optional message. - `data` - optional additional error data. ```js Boom.uriTooLong('uri is too long'); ``` Generates the following response payload: ```json { "statusCode": 414, "error": "Request-URI Too Large", "message": "uri is too long" } ``` ##### `Boom.unsupportedMediaType([message], [data])` Returns a 415 Unsupported Media Type error where: - `message` - optional message. - `data` - optional additional error data. ```js Boom.unsupportedMediaType('that media is not supported'); ``` Generates the following response payload: ```json { "statusCode": 415, "error": "Unsupported Media Type", "message": "that media is not supported" } ``` ##### `Boom.rangeNotSatisfiable([message], [data])` Returns a 416 Requested Range Not Satisfiable error where: - `message` - optional message. - `data` - optional additional error data. ```js Boom.rangeNotSatisfiable(); ``` Generates the following response payload: ```json { "statusCode": 416, "error": "Requested Range Not Satisfiable" } ``` ##### `Boom.expectationFailed([message], [data])` Returns a 417 Expectation Failed error where: - `message` - optional message. - `data` - optional additional error data. ```js Boom.expectationFailed('expected this to work'); ``` Generates the following response payload: ```json { "statusCode": 417, "error": "Expectation Failed", "message": "expected this to work" } ``` ##### `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: - `message` - optional message. - `data` - optional additional error data. ```js Boom.badData('your data is bad and you should feel bad'); ``` Generates the following response payload: ```json { "statusCode": 422, "error": "Unprocessable Entity", "message": "your data is bad and you should feel bad" } ``` ##### `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.failedDependency([message], [data])` Returns a 424 Failed Dependency error where: - `message` - optional message. - `data` - optional additional error data. ```js Boom.failedDependency('an external resource failed'); ``` Generates the following response payload: ```json { "statusCode": 424, "error": "Failed Dependency", "message": "an external resource failed" } ``` ##### `Boom.tooEarly([message], [data])` Returns a 425 Too Early error where: - `message` - optional message. - `data` - optional additional error data. ```js Boom.tooEarly('the server is unwilling to risk processing the request'); ``` Generates the following response payload: ```json { "statusCode": 425, "error": "Too Early", "message": "the server is unwilling to risk processing the request" } ``` ##### `Boom.preconditionRequired([message], [data])` Returns a 428 Precondition Required error where: - `message` - optional message. - `data` - optional additional error data. ```js Boom.preconditionRequired('you must supply an If-Match header'); ``` Generates the following response payload: ```json { "statusCode": 428, "error": "Precondition Required", "message": "you must supply an If-Match header" } ``` ##### `Boom.tooManyRequests([message], [data])` Returns a 429 Too Many Requests error where: - `message` - optional message. - `data` - optional additional error data. ```js Boom.tooManyRequests('you have exceeded your request limit'); ``` Generates the following response payload: ```json { "statusCode": 429, "error": "Too Many Requests", "message": "you have exceeded your request limit" } ``` ##### `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. ##### `Boom.badImplementation([message], [data])` - (*alias: `internal`*) Returns a 500 Internal Server Error error where: - `message` - optional message. - `data` - optional additional error data. ```js Boom.badImplementation('terrible implementation'); ``` Generates the following response payload: ```json { "statusCode": 500, "error": "Internal Server Error", "message": "An internal server error occurred" } ``` ##### `Boom.notImplemented([message], [data])` Returns a 501 Not Implemented error where: - `message` - optional message. - `data` - optional additional error data. ```js Boom.notImplemented('method not implemented'); ``` Generates the following response payload: ```json { "statusCode": 501, "error": "Not Implemented", "message": "method not implemented" } ``` ##### `Boom.badGateway([message], [data])` Returns a 502 Bad Gateway error where: - `message` - optional message. - `data` - optional additional error data. ```js Boom.badGateway('that is a bad gateway'); ``` Generates the following response payload: ```json { "statusCode": 502, "error": "Bad Gateway", "message": "that is a bad gateway" } ``` ##### `Boom.serverUnavailable([message], [data])` Returns a 503 Service Unavailable error where: - `message` - optional message. - `data` - optional additional error data. ```js Boom.serverUnavailable('unavailable'); ``` Generates the following response payload: ```json { "statusCode": 503, "error": "Service Unavailable", "message": "unavailable" } ``` ##### `Boom.gatewayTimeout([message], [data])` Returns a 504 Gateway Time-out error where: - `message` - optional message. - `data` - optional additional error data. ```js Boom.gatewayTimeout(); ``` Generates the following response payload: ```json { "statusCode": 504, "error": "Gateway Time-out" } ``` #### F.A.Q. **Q** How do I include extra information in my responses? `output.payload` is missing `data`, what gives? **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. boom-10.0.1/LICENSE.md000077500000000000000000000027611437175134500141540ustar00rootroot00000000000000Copyright (c) 2012-2022, Project contributors Copyright (c) 2012-2020, Sideway Inc Copyright (c) 2012-2014, Walmart. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * The names of any contributors may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS OFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. boom-10.0.1/README.md000077500000000000000000000017641437175134500140310ustar00rootroot00000000000000 # @hapi/boom #### HTTP-friendly error objects. **boom** is part of the **hapi** ecosystem and was designed to work seamlessly with the [hapi web framework](https://hapi.dev) and its other components (but works great on its own or with other frameworks). If you are using a different web framework and find this module useful, check out [hapi](https://hapi.dev) – they work even better together. ### Visit the [hapi.dev](https://hapi.dev) Developer Portal for tutorials, documentation, and support ## Useful resources - [Documentation and API](https://hapi.dev/family/boom/) - [Version status](https://hapi.dev/resources/status/#boom) (builds, dependencies, node versions, licenses, eol) - [Changelog](https://hapi.dev/family/boom/changelog/) - [Project policies](https://hapi.dev/policies/) - [Free and commercial support options](https://hapi.dev/support/) boom-10.0.1/lib/000077500000000000000000000000001437175134500133055ustar00rootroot00000000000000boom-10.0.1/lib/index.d.ts000077500000000000000000000327011437175134500152140ustar00rootroot00000000000000/** * An Error object used to return an HTTP response error (4xx, 5xx) */ export class Boom extends Error { /** * Creates a new Boom object using the provided message or Error */ constructor(message?: string | Error, options?: Options); /** * Custom error data with additional information specific to the error type */ data?: Data; /** * isBoom - if true, indicates this is a Boom object instance. */ isBoom: boolean; /** * Convenience boolean indicating status code >= 500 */ isServer: boolean; /** * The error message */ message: string; /** * The formatted response */ output: Output; /** * The constructor used to create the error */ typeof: Function; /** * Specifies if an error object is a valid boom object * * @param debug - A boolean that, when true, does not hide the original 500 error message. Defaults to false. */ reformat(debug?: boolean): string; } export interface Options { /** * The HTTP status code * * @default 500 */ statusCode?: number; /** * Additional error information */ data?: Data; /** * Constructor reference used to crop the exception call stack output */ ctor?: Function; /** * Error message string * * @default none */ message?: string; /** * If false, the err provided is a Boom object, and a statusCode or message are provided, the values are ignored * * @default true */ override?: boolean; } export interface Decorate { /** * An option with extra properties to set on the error object */ decorate?: Decoration; } export interface Payload { /** * The HTTP status code derived from error.output.statusCode */ statusCode: number; /** * The HTTP status message derived from statusCode */ error: string; /** * The error message derived from error.message */ message: string; /** * Custom properties */ [key: string]: unknown; } export interface Output { /** * The HTTP status code */ statusCode: number; /** * An object containing any HTTP headers where each key is a header name and value is the header content */ headers: { [header: string]: string | string[] | number | undefined }; /** * The formatted object used as the response payload (stringified) */ payload: Payload; } /** * Specifies if an object is a valid boom object * * @param obj - The object to assess * @param statusCode - Optional status code * * @returns Returns a boolean stating if the error object is a valid boom object and it has the provided statusCode (if present) */ export function isBoom(obj: unknown, statusCode?: number): obj is Boom; /** * Specifies if an error object is a valid boom object * * @param err - The error object to decorate * @param options - Options object * * @returns A decorated boom object */ export function boomify(err: Error, options?: Options & Decorate): Boom & Decoration; // 4xx Errors /** * Returns a 400 Bad Request error * * @param messageOrError - Optional message or Error * @param data - Optional additional error data * * @returns A 400 bad request error */ export function badRequest(messageOrError?: string | Error, data?: Data): Boom; /** * Returns a 401 Unauthorized error * * @param messageOrError - Optional message or Error * * @returns A 401 Unauthorized error */ export function unauthorized(messageOrError?: string | Error | null): Boom; /** * Returns a 401 Unauthorized error * * @param message - Optional message * @param scheme - the authentication scheme name * @param attributes - an object of values used to construct the 'WWW-Authenticate' header * * @returns A 401 Unauthorized error */ export function unauthorized(message: '' | null, scheme: string, attributes?: string | unauthorized.Attributes): Boom & unauthorized.MissingAuth; export function unauthorized(message: string | null, scheme: string, attributes?: string | unauthorized.Attributes): Boom; export namespace unauthorized { interface Attributes { [index: string]: number | string | null | undefined; } interface MissingAuth { /** * Indicate whether the 401 unauthorized error is due to missing credentials (vs. invalid) */ isMissing: boolean; } } /** * Returns a 401 Unauthorized error * * @param message - Optional message * @param wwwAuthenticate - array of string values used to construct the wwwAuthenticate header * * @returns A 401 Unauthorized error */ export function unauthorized(message: string | null, wwwAuthenticate: string[]): Boom; /** * Returns a 402 Payment Required error * * @param messageOrError - Optional message or Error * @param data - Optional additional error data * * @returns A 402 Payment Required error */ export function paymentRequired(messageOrError?: string | Error, data?: Data): Boom; /** * Returns a 403 Forbidden error * * @param messageOrError - Optional message or Error * @param data - Optional additional error data * * @returns A 403 Forbidden error */ export function forbidden(messageOrError?: string | Error, data?: Data): Boom; /** * Returns a 404 Not Found error * * @param messageOrError - Optional message or Error * @param data - Optional additional error data * * @returns A 404 Not Found error */ export function notFound(messageOrError?: string | Error, data?: Data): Boom; /** * Returns a 405 Method Not Allowed error * * @param messageOrError - Optional message or Error * @param data - Optional additional error data * @param allow - Optional string or array of strings which is used to set the 'Allow' header * * @returns A 405 Method Not Allowed error */ export function methodNotAllowed(messageOrError?: string | Error, data?: Data, allow?: string | string[]): Boom; /** * Returns a 406 Not Acceptable error * * @param messageOrError - Optional message or Error * @param data - Optional additional error data * * @returns A 406 Not Acceptable error */ export function notAcceptable(messageOrError?: string | Error, data?: Data): Boom; /** * Returns a 407 Proxy Authentication error * * @param messageOrError - Optional message or Error * @param data - Optional additional error data * * @returns A 407 Proxy Authentication error */ export function proxyAuthRequired(messageOrError?: string | Error, data?: Data): Boom; /** * Returns a 408 Request Time-out error * * @param messageOrError - Optional message or Error * @param data - Optional additional error data * * @returns A 408 Request Time-out error */ export function clientTimeout(messageOrError?: string | Error, data?: Data): Boom; /** * Returns a 409 Conflict error * * @param messageOrError - Optional message or Error * @param data - Optional additional error data * * @returns A 409 Conflict error */ export function conflict(messageOrError?: string | Error, data?: Data): Boom; /** * Returns a 410 Gone error * * @param messageOrError - Optional message or Error * @param data - Optional additional error data * * @returns A 410 gone error */ export function resourceGone(messageOrError?: string | Error, data?: Data): Boom; /** * Returns a 411 Length Required error * * @param messageOrError - Optional message or Error * @param data - Optional additional error data * * @returns A 411 Length Required error */ export function lengthRequired(messageOrError?: string | Error, data?: Data): Boom; /** * Returns a 412 Precondition Failed error * * @param messageOrError - Optional message or Error * @param data - Optional additional error data * * @returns A 412 Precondition Failed error */ export function preconditionFailed(messageOrError?: string | Error, data?: Data): Boom; /** * Returns a 413 Request Entity Too Large error * * @param messageOrError - Optional message or Error * @param data - Optional additional error data * * @returns A 413 Request Entity Too Large error */ export function entityTooLarge(messageOrError?: string | Error, data?: Data): Boom; /** * Returns a 414 Request-URI Too Large error * * @param messageOrError - Optional message or Error * @param data - Optional additional error data * * @returns A 414 Request-URI Too Large error */ export function uriTooLong(messageOrError?: string | Error, data?: Data): Boom; /** * Returns a 415 Unsupported Media Type error * * @param messageOrError - Optional message or Error * @param data - Optional additional error data * * @returns A 415 Unsupported Media Type error */ export function unsupportedMediaType(messageOrError?: string | Error, data?: Data): Boom; /** * Returns a 416 Request Range Not Satisfiable error * * @param messageOrError - Optional message or Error * @param data - Optional additional error data * * @returns A 416 Request Range Not Satisfiable error */ export function rangeNotSatisfiable(messageOrError?: string | Error, data?: Data): Boom; /** * Returns a 417 Expectation Failed error * * @param messageOrError - Optional message or Error * @param data - Optional additional error data * * @returns A 417 Expectation Failed error */ export function expectationFailed(messageOrError?: string | Error, data?: Data): Boom; /** * Returns a 418 I'm a Teapot error * * @param messageOrError - Optional message or Error * @param data - Optional additional error data * * @returns A 418 I'm a Teapot error */ export function teapot(messageOrError?: string | Error, data?: Data): Boom; /** * Returns a 422 Unprocessable Entity error * * @param messageOrError - Optional message or Error * @param data - Optional additional error data * * @returns A 422 Unprocessable Entity error */ export function badData(messageOrError?: string | Error, data?: Data): Boom; /** * Returns a 423 Locked error * * @param messageOrError - Optional message or Error * @param data - Optional additional error data * * @returns A 423 Locked error */ export function locked(messageOrError?: string | Error, data?: Data): Boom; /** * Returns a 424 Failed Dependency error * * @param messageOrError - Optional message or Error * @param data - Optional additional error data * * @returns A 424 Failed Dependency error */ export function failedDependency(messageOrError?: string | Error, data?: Data): Boom; /** * Returns a 425 Too Early error * * @param messageOrError - Optional message or Error * @param data - Optional additional error data * * @returns A 425 Too Early error */ export function tooEarly(messageOrError?: string | Error, data?: Data): Boom; /** * Returns a 428 Precondition Required error * * @param messageOrError - Optional message or Error * @param data - Optional additional error data * * @returns A 428 Precondition Required error */ export function preconditionRequired(messageOrError?: string | Error, data?: Data): Boom; /** * Returns a 429 Too Many Requests error * * @param messageOrError - Optional message or Error * @param data - Optional additional error data * * @returns A 429 Too Many Requests error */ export function tooManyRequests(messageOrError?: string | Error, data?: Data): Boom; /** * Returns a 451 Unavailable For Legal Reasons error * * @param messageOrError - Optional message or Error * @param data - Optional additional error data * * @returns A 451 Unavailable for Legal Reasons error */ export function illegal(messageOrError?: string | Error, data?: Data): Boom; // 5xx Errors /** * Returns a internal error (defaults to 500) * * @param messageOrError - Optional message or Error * @param data - Optional additional error data * @param statusCode - Optional status code override. Defaults to 500. * * @returns A 500 Internal Server error */ export function internal(messageOrError?: string | Error, data?: Data, statusCode?: number): Boom; /** * Returns a 500 Internal Server Error error * * @param messageOrError - Optional message or Error * @param data - Optional additional error data * * @returns A 500 Internal Server error */ export function badImplementation(messageOrError?: string | Error, data?: Data): Boom; /** * Returns a 501 Not Implemented error * * @param messageOrError - Optional message or Error * @param data - Optional additional error data * * @returns A 501 Not Implemented error */ export function notImplemented(messageOrError?: string | Error, data?: Data): Boom; /** * Returns a 502 Bad Gateway error * * @param messageOrError - Optional message or Error * @param data - Optional additional error data * * @returns A 502 Bad Gateway error */ export function badGateway(messageOrError?: string | Error, data?: Data): Boom; /** * Returns a 503 Service Unavailable error * * @param messageOrError - Optional message or Error * @param data - Optional additional error data * * @returns A 503 Service Unavailable error */ export function serverUnavailable(messageOrError?: string | Error, data?: Data): Boom; /** * Returns a 504 Gateway Time-out error * * @param messageOrError - Optional message or Error * @param data - Optional additional error data * * @returns A 504 Gateway Time-out error */ export function gatewayTimeout(messageOrError?: string | Error, data?: Data): Boom; boom-10.0.1/lib/index.js000077500000000000000000000306611437175134500147630ustar00rootroot00000000000000'use strict'; const Hoek = require('@hapi/hoek'); const internals = { codes: new Map([ [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, 'Too Early'], [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'] ]) }; exports.Boom = class extends Error { constructor(messageOrError, options = {}) { if (messageOrError instanceof Error) { return exports.boomify(Hoek.clone(messageOrError), options); } const { statusCode = 500, data = null, ctor = exports.Boom } = options; const error = new Error(messageOrError ? messageOrError : undefined); // Avoids settings null message Error.captureStackTrace(error, ctor); // Filter the stack to our external API error.data = data; const boom = internals.initialize(error, statusCode); Object.defineProperty(boom, 'typeof', { value: ctor }); if (options.decorate) { Object.assign(boom, options.decorate); } return boom; } static [Symbol.hasInstance](instance) { if (this === exports.Boom) { return exports.isBoom(instance); } // Cannot use 'instanceof' as it creates infinite recursion return this.prototype.isPrototypeOf(instance); } }; exports.isBoom = function (err, statusCode) { return err instanceof Error && !!err.isBoom && (!statusCode || err.output.statusCode === statusCode); }; exports.boomify = function (err, options) { Hoek.assert(err instanceof Error, 'Cannot wrap non-Error object'); options = options || {}; if (options.data !== undefined) { err.data = options.data; } if (options.decorate) { Object.assign(err, options.decorate); } if (!err.isBoom) { return internals.initialize(err, options.statusCode ?? 500, options.message); } if (options.override === false || // Defaults to true !options.statusCode && !options.message) { return err; } return internals.initialize(err, options.statusCode ?? err.output.statusCode, options.message); }; // 4xx Client Errors exports.badRequest = function (messageOrError, data) { return new exports.Boom(messageOrError, { statusCode: 400, data, ctor: exports.badRequest }); }; exports.unauthorized = function (message, scheme, attributes) { // Or (message, wwwAuthenticate[]) const err = new exports.Boom(message, { statusCode: 401, ctor: exports.unauthorized }); // function (message) if (!scheme) { return err; } // function (message, wwwAuthenticate[]) if (typeof scheme !== 'string') { err.output.headers['WWW-Authenticate'] = scheme.join(', '); return err; } // function (message, scheme, attributes) let wwwAuthenticate = `${scheme}`; if (attributes || message) { err.output.payload.attributes = {}; } if (attributes) { if (typeof attributes === 'string') { wwwAuthenticate += ' ' + Hoek.escapeHeaderAttribute(attributes); err.output.payload.attributes = attributes; } else { wwwAuthenticate += ' ' + Object.keys(attributes).map((name) => { const value = attributes[name] ?? ''; err.output.payload.attributes[name] = value; return `${name}="${Hoek.escapeHeaderAttribute(value.toString())}"`; }) .join(', '); } } if (message) { if (attributes) { wwwAuthenticate += ','; } wwwAuthenticate += ` error="${Hoek.escapeHeaderAttribute(message)}"`; err.output.payload.attributes.error = message; } else { err.isMissing = true; } err.output.headers['WWW-Authenticate'] = wwwAuthenticate; return err; }; exports.paymentRequired = function (messageOrError, data) { return new exports.Boom(messageOrError, { statusCode: 402, data, ctor: exports.paymentRequired }); }; exports.forbidden = function (messageOrError, data) { return new exports.Boom(messageOrError, { statusCode: 403, data, ctor: exports.forbidden }); }; exports.notFound = function (messageOrError, data) { return new exports.Boom(messageOrError, { statusCode: 404, data, ctor: exports.notFound }); }; exports.methodNotAllowed = function (messageOrError, data, allow) { const err = new exports.Boom(messageOrError, { statusCode: 405, data, ctor: exports.methodNotAllowed }); if (typeof allow === 'string') { allow = [allow]; } if (Array.isArray(allow)) { err.output.headers.Allow = allow.join(', '); } return err; }; exports.notAcceptable = function (messageOrError, data) { return new exports.Boom(messageOrError, { statusCode: 406, data, ctor: exports.notAcceptable }); }; exports.proxyAuthRequired = function (messageOrError, data) { return new exports.Boom(messageOrError, { statusCode: 407, data, ctor: exports.proxyAuthRequired }); }; exports.clientTimeout = function (messageOrError, data) { return new exports.Boom(messageOrError, { statusCode: 408, data, ctor: exports.clientTimeout }); }; exports.conflict = function (messageOrError, data) { return new exports.Boom(messageOrError, { statusCode: 409, data, ctor: exports.conflict }); }; exports.resourceGone = function (messageOrError, data) { return new exports.Boom(messageOrError, { statusCode: 410, data, ctor: exports.resourceGone }); }; exports.lengthRequired = function (messageOrError, data) { return new exports.Boom(messageOrError, { statusCode: 411, data, ctor: exports.lengthRequired }); }; exports.preconditionFailed = function (messageOrError, data) { return new exports.Boom(messageOrError, { statusCode: 412, data, ctor: exports.preconditionFailed }); }; exports.entityTooLarge = function (messageOrError, data) { return new exports.Boom(messageOrError, { statusCode: 413, data, ctor: exports.entityTooLarge }); }; exports.uriTooLong = function (messageOrError, data) { return new exports.Boom(messageOrError, { statusCode: 414, data, ctor: exports.uriTooLong }); }; exports.unsupportedMediaType = function (messageOrError, data) { return new exports.Boom(messageOrError, { statusCode: 415, data, ctor: exports.unsupportedMediaType }); }; exports.rangeNotSatisfiable = function (messageOrError, data) { return new exports.Boom(messageOrError, { statusCode: 416, data, ctor: exports.rangeNotSatisfiable }); }; exports.expectationFailed = function (messageOrError, data) { return new exports.Boom(messageOrError, { statusCode: 417, data, ctor: exports.expectationFailed }); }; exports.teapot = function (messageOrError, data) { return new exports.Boom(messageOrError, { statusCode: 418, data, ctor: exports.teapot }); }; exports.badData = function (messageOrError, data) { return new exports.Boom(messageOrError, { statusCode: 422, data, ctor: exports.badData }); }; exports.locked = function (messageOrError, data) { return new exports.Boom(messageOrError, { statusCode: 423, data, ctor: exports.locked }); }; exports.failedDependency = function (messageOrError, data) { return new exports.Boom(messageOrError, { statusCode: 424, data, ctor: exports.failedDependency }); }; exports.tooEarly = function (messageOrError, data) { return new exports.Boom(messageOrError, { statusCode: 425, data, ctor: exports.tooEarly }); }; exports.preconditionRequired = function (messageOrError, data) { return new exports.Boom(messageOrError, { statusCode: 428, data, ctor: exports.preconditionRequired }); }; exports.tooManyRequests = function (messageOrError, data) { return new exports.Boom(messageOrError, { statusCode: 429, data, ctor: exports.tooManyRequests }); }; exports.illegal = function (messageOrError, data) { return new exports.Boom(messageOrError, { statusCode: 451, data, ctor: exports.illegal }); }; // 5xx Server Errors exports.internal = function (message, data, statusCode = 500) { return internals.serverError(message, data, statusCode, exports.internal); }; exports.notImplemented = function (message, data) { return internals.serverError(message, data, 501, exports.notImplemented); }; exports.badGateway = function (message, data) { return internals.serverError(message, data, 502, exports.badGateway); }; exports.serverUnavailable = function (message, data) { return internals.serverError(message, data, 503, exports.serverUnavailable); }; exports.gatewayTimeout = function (message, data) { return internals.serverError(message, data, 504, exports.gatewayTimeout); }; exports.badImplementation = function (message, data) { const err = internals.serverError(message, data, 500, exports.badImplementation); err.isDeveloperError = true; return err; }; internals.initialize = function (err, statusCode, message) { const numberCode = parseInt(statusCode, 10); Hoek.assert(!isNaN(numberCode) && numberCode >= 400, 'First argument must be a number (400+):', statusCode); err.isBoom = true; err.isServer = numberCode >= 500; if (!err.hasOwnProperty('data')) { err.data = null; } err.output = { statusCode: numberCode, payload: {}, headers: {} }; Object.defineProperty(err, 'reformat', { value: internals.reformat, configurable: true }); if (!message && !err.message) { err.reformat(); message = err.output.payload.error; } if (message) { const props = Object.getOwnPropertyDescriptor(err, 'message') || Object.getOwnPropertyDescriptor(Object.getPrototypeOf(err), 'message'); Hoek.assert(!props || props.configurable && !props.get, 'The error is not compatible with boom'); err.message = message + (err.message ? ': ' + err.message : ''); err.output.payload.message = err.message; } err.reformat(); return err; }; internals.reformat = function (debug = false) { this.output.payload.statusCode = this.output.statusCode; this.output.payload.error = internals.codes.get(this.output.statusCode) || 'Unknown'; if (this.output.statusCode === 500 && debug !== true) { this.output.payload.message = 'An internal server error occurred'; // Hide actual error from user } else if (this.message) { this.output.payload.message = this.message; } }; internals.serverError = function (messageOrError, data, statusCode, ctor) { if (data instanceof Error && !data.isBoom) { return exports.boomify(data, { statusCode, message: messageOrError }); } return new exports.Boom(messageOrError, { statusCode, data, ctor }); }; boom-10.0.1/package.json000066400000000000000000000013531437175134500150270ustar00rootroot00000000000000{ "name": "@hapi/boom", "description": "HTTP-friendly error objects", "version": "10.0.1", "repository": "git://github.com/hapijs/boom", "main": "lib/index.js", "types": "lib/index.d.ts", "keywords": [ "error", "http" ], "files": [ "lib" ], "eslintConfig": { "extends": [ "plugin:@hapi/module" ] }, "dependencies": { "@hapi/hoek": "^11.0.2" }, "devDependencies": { "@hapi/code": "9.x.x", "@hapi/eslint-plugin": "*", "@hapi/lab": "^25.1.0", "@types/node": "^17.0.31", "typescript": "~4.6.4" }, "scripts": { "test": "lab -a @hapi/code -t 100 -L -Y", "test-cov-html": "lab -a @hapi/code -t 100 -L -r html -o coverage.html" }, "license": "BSD-3-Clause" } boom-10.0.1/test/000077500000000000000000000000001437175134500135165ustar00rootroot00000000000000boom-10.0.1/test/index.js000077500000000000000000001025331437175134500151720ustar00rootroot00000000000000'use strict'; const Boom = require('..'); const Code = require('@hapi/code'); const Lab = require('@hapi/lab'); const internals = {}; const { describe, it } = exports.lab = Lab.script(); const expect = Code.expect; describe('Boom', () => { it('constructs error object (new)', () => { const err = new Boom.Boom('oops', { statusCode: 400 }); expect(err.output.payload.message).to.equal('oops'); expect(err.output.statusCode).to.equal(400); expect(Object.keys(err)).to.equal(['data', 'isBoom', 'isServer', 'output']); expect(JSON.stringify(err)).to.equal('{"data":null,"isBoom":true,"isServer":false,"output":{"statusCode":400,"payload":{"statusCode":400,"error":"Bad Request","message":"oops"},"headers":{}}}'); }); it('clones error object', () => { const oops = new Error('oops'); const err = new Boom.Boom(oops, { statusCode: 400 }); expect(err).to.not.shallow.equal(oops); expect(err.output.payload.message).to.equal('oops'); expect(err.output.statusCode).to.equal(400); }); it('decorates error', () => { const err = new Boom.Boom('oops', { statusCode: 400, decorate: { x: 1 } }); expect(err.output.payload.message).to.equal('oops'); expect(err.output.statusCode).to.equal(400); expect(err.x).to.equal(1); }); it('handles missing message', () => { const err = new Error(); Boom.boomify(err); expect(Boom.isBoom(err)).to.be.true(); }); it('handles missing message (class)', () => { const Example = class extends Error { constructor(message) { super(message); Boom.boomify(this); } }; const err = new Example(); expect(Boom.isBoom(err)).to.be.true(); }); it('throws when statusCode is not a number', () => { expect(() => { new Boom.Boom('message', { statusCode: 'x' }); }).to.throw('First argument must be a number (400+): x'); }); it('errors on incompatible message property (prototype)', () => { const Err = class extends Error { get message() { return 'x'; } }; const err = new Err(); expect(() => Boom.boomify(err, { message: 'override' })).to.throw('The error is not compatible with boom'); }); it('errors on incompatible message property (own)', () => { const err = new Error(); Object.defineProperty(err, 'message', { get: function () { } }); expect(() => Boom.boomify(err, { message: 'override' })).to.throw('The error is not compatible with boom'); }); it('will cast a number-string to an integer', () => { const codes = [ { input: '404', result: 404 }, { input: '404.1', result: 404 }, { input: 400, result: 400 }, { input: 400.123, result: 400 } ]; for (let i = 0; i < codes.length; ++i) { const code = codes[i]; const err = new Boom.Boom('', { statusCode: code.input }); expect(err.output.statusCode).to.equal(code.result); } }); it('throws when statusCode is not finite', () => { expect(() => { new Boom.Boom('', { statusCode: 1 / 0 }); }).to.throw('First argument must be a number (400+): null'); }); it('sets error code to unknown', () => { const err = new Boom.Boom('', { statusCode: 999 }); expect(err.output.payload.error).to.equal('Unknown'); }); describe('instanceof', () => { it('identifies a boom object', () => { const BadaBoom = class extends Boom.Boom { }; expect(new Boom.Boom('oops')).to.be.instanceOf(Boom.Boom); expect(new BadaBoom('oops')).to.be.instanceOf(Boom.Boom); expect(Boom.badRequest('oops')).to.be.instanceOf(Boom.Boom); expect(new Error('oops')).to.not.be.instanceOf(Boom.Boom); expect(Boom.boomify(new Error('oops'))).to.be.instanceOf(Boom.Boom); expect({ isBoom: true }).to.not.be.instanceOf(Boom.Boom); expect(null).to.not.be.instanceOf(Boom.Boom); }); it('returns false when called on sub-class', () => { const BadaBoom = class extends Boom.Boom {}; expect(new Boom.Boom('oops')).to.not.be.instanceOf(BadaBoom); expect(new BadaBoom('oops')).to.not.be.instanceOf(BadaBoom); expect(Boom.badRequest('oops')).to.not.be.instanceOf(BadaBoom); expect(Boom.boomify(new Error('oops'))).to.not.be.instanceOf(BadaBoom); }); it('handles actual sub-class instances when called on sub-class', () => { const BadaBoom = class extends Boom.Boom { }; expect(Object.create(BadaBoom.prototype)).to.be.instanceOf(BadaBoom); }); }); describe('isBoom()', () => { it('identifies a boom object', () => { expect(Boom.isBoom(new Boom.Boom('oops'))).to.be.true(); expect(Boom.isBoom(new Error('oops'))).to.be.false(); expect(Boom.isBoom({ isBoom: true })).to.be.false(); expect(Boom.isBoom(null)).to.be.false(); }); it('returns true for valid boom object and valid status code', () => { expect(Boom.isBoom(Boom.notFound(),404)).to.be.true(); }); it('returns false for valid boom object and wrong status code', () => { expect(Boom.isBoom(Boom.notFound(),503)).to.be.false(); }); }); describe('boomify()', () => { it('returns the same object when already boom', () => { const error = Boom.badRequest(); expect(error).to.equal(Boom.boomify(error)); expect(error).to.equal(Boom.boomify(error, { statusCode: 444 })); }); it('decorates error', () => { const err = new Error('oops'); Boom.boomify(err, { statusCode: 400, decorate: { x: 1 } }); expect(err.x).to.equal(1); }); it('returns an error with info when constructed using another error', () => { const error = new Error('ka-boom'); error.xyz = 123; const err = Boom.boomify(error); expect(err.xyz).to.equal(123); expect(err.message).to.equal('ka-boom'); expect(err.output).to.equal({ statusCode: 500, payload: { statusCode: 500, error: 'Internal Server Error', message: 'An internal server error occurred' }, headers: {} }); expect(err.data).to.equal(null); }); it('does not override data when constructed using another error', () => { const error = new Error('ka-boom'); error.data = { useful: 'data' }; const err = Boom.boomify(error); expect(err.data).to.equal(error.data); }); it('sets new message when none exists', () => { const error = new Error(); const wrapped = Boom.boomify(error, { statusCode: 400, message: 'something bad' }); expect(wrapped.message).to.equal('something bad'); }); it('returns boom error unchanged', () => { const error = Boom.badRequest('Missing data', { type: 'user' }); const boom = Boom.boomify(error); expect(boom).to.shallow.equal(error); expect(error.data.type).to.equal('user'); expect(error.output.payload.message).to.equal('Missing data'); expect(error.output.statusCode).to.equal(400); }); it('defaults to 500', () => { const error = new Error('Missing data'); const boom = Boom.boomify(error); expect(boom).to.shallow.equal(error); expect(error.output.payload.message).to.equal('An internal server error occurred'); expect(error.output.statusCode).to.equal(500); }); it('overrides message and statusCode', () => { const error = Boom.badRequest('Missing data', { type: 'user' }); const boom = Boom.boomify(error, { message: 'Override message', statusCode: 599 }); expect(boom).to.shallow.equal(error); expect(error.data.type).to.equal('user'); expect(error.output.payload.message).to.equal('Override message: Missing data'); expect(error.output.statusCode).to.equal(599); }); it('overrides message', () => { const error = Boom.badRequest('Missing data', { type: 'user' }); const boom = Boom.boomify(error, { message: 'Override message' }); expect(boom).to.shallow.equal(error); expect(error.data.type).to.equal('user'); expect(error.output.payload.message).to.equal('Override message: Missing data'); expect(error.output.statusCode).to.equal(400); }); it('overrides statusCode', () => { const error = Boom.badRequest('Missing data', { type: 'user' }); const boom = Boom.boomify(error, { statusCode: 599 }); expect(boom).to.shallow.equal(error); expect(error.data.type).to.equal('user'); expect(error.output.payload.message).to.equal('Missing data'); expect(error.output.statusCode).to.equal(599); }); it('skips override', () => { const error = Boom.badRequest('Missing data', { type: 'user' }); const boom = Boom.boomify(error, { message: 'Override message', statusCode: 599, override: false }); expect(boom).to.shallow.equal(error); expect(error.data.type).to.equal('user'); expect(error.output.payload.message).to.equal('Missing data'); expect(error.output.statusCode).to.equal(400); }); it('initializes plain error', () => { const error = new Error('Missing data'); const boom = Boom.boomify(error, { message: 'Override message', statusCode: 599, override: false }); expect(boom).to.shallow.equal(error); expect(error.output.payload.message).to.equal('Override message: Missing data'); expect(error.output.statusCode).to.equal(599); }); }); describe('create()', () => { it('does not sets null message', () => { const error = Boom.unauthorized(null); expect(error.output.payload.message).to.equal('Unauthorized'); expect(error.isServer).to.be.false(); }); it('sets message and data', () => { const error = Boom.badRequest('Missing data', { type: 'user' }); expect(error.data.type).to.equal('user'); expect(error.output.payload.message).to.equal('Missing data'); }); }); describe('initialize()', () => { it('does not sets null message', () => { const err = new Error('some error message'); const boom = Boom.boomify(err, { statusCode: 400, message: 'modified error message' }); expect(boom.output.payload.message).to.equal('modified error message: some error message'); }); }); describe('isBoom()', () => { it('returns true for Boom object', () => { expect(Boom.badRequest().isBoom).to.equal(true); }); it('returns false for Error object', () => { expect((new Error()).isBoom).to.not.exist(); }); }); describe('badRequest()', () => { it('returns a 400 error statusCode', () => { const error = Boom.badRequest(); expect(error.output.statusCode).to.equal(400); expect(error.isServer).to.be.false(); }); it('sets the message with the passed in message', () => { expect(Boom.badRequest('my message').message).to.equal('my message'); }); it('sets the message to HTTP status if none provided', () => { expect(Boom.badRequest().message).to.equal('Bad Request'); }); }); describe('unauthorized()', () => { it('returns a 401 error statusCode', () => { const err = Boom.unauthorized(); expect(err.output.statusCode).to.equal(401); expect(err.output.headers).to.equal({}); }); it('sets the message with the passed in message', () => { expect(Boom.unauthorized('my message').message).to.equal('my message'); }); it('returns a WWW-Authenticate header when passed a scheme', () => { const err = Boom.unauthorized('boom', 'Test'); expect(err.output.statusCode).to.equal(401); expect(err.output.headers['WWW-Authenticate']).to.equal('Test error="boom"'); }); it('returns a WWW-Authenticate header when passed a scheme (no message)', () => { const err = Boom.unauthorized(null, 'Test'); expect(err.output.statusCode).to.equal(401); expect(err.output.headers['WWW-Authenticate']).to.equal('Test'); }); it('returns a WWW-Authenticate header set to the schema array value', () => { const 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'); }); it('returns a WWW-Authenticate header when passed a scheme and attributes', () => { const 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.equal({ a: 1, b: 'something', c: '', d: 0, error: 'boom' }); }); it('returns a WWW-Authenticate header from string input instead of object', () => { const err = Boom.unauthorized(null, 'Negotiate', 'VGhpcyBpcyBhIHRlc3QgdG9rZW4='); expect(err.output.statusCode).to.equal(401); expect(err.output.headers['WWW-Authenticate']).to.equal('Negotiate VGhpcyBpcyBhIHRlc3QgdG9rZW4='); expect(err.output.payload.attributes).to.equal('VGhpcyBpcyBhIHRlc3QgdG9rZW4='); }); it('returns a WWW-Authenticate header when passed attributes, missing error', () => { const err = Boom.unauthorized(null, 'Test', { a: 1, b: 'something', c: null, d: 0, e: undefined }); expect(err.output.statusCode).to.equal(401); expect(err.output.headers['WWW-Authenticate']).to.equal('Test a="1", b="something", c="", d="0", e=""'); expect(err.isMissing).to.equal(true); }); it('sets the isMissing flag when error message is empty', () => { const err = Boom.unauthorized('', 'Basic'); expect(err.isMissing).to.equal(true); }); it('does not set the isMissing flag when error message is not empty', () => { const err = Boom.unauthorized('message', 'Basic'); expect(err.isMissing).to.equal(undefined); }); it('sets a WWW-Authenticate when passed as an array', () => { const 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"'); }); }); describe('paymentRequired()', () => { it('returns a 402 error statusCode', () => { expect(Boom.paymentRequired().output.statusCode).to.equal(402); }); it('sets the message with the passed in message', () => { expect(Boom.paymentRequired('my message').message).to.equal('my message'); }); it('sets the message to HTTP status if none provided', () => { expect(Boom.paymentRequired().message).to.equal('Payment Required'); }); }); describe('methodNotAllowed()', () => { it('returns a 405 error statusCode', () => { expect(Boom.methodNotAllowed().output.statusCode).to.equal(405); }); it('sets the message with the passed in message', () => { expect(Boom.methodNotAllowed('my message').message).to.equal('my message'); }); it('returns an Allow header when passed a string', () => { const err = Boom.methodNotAllowed('my message', null, 'GET'); expect(err.output.statusCode).to.equal(405); expect(err.output.headers.Allow).to.equal('GET'); }); it('returns an Allow header when passed an array', () => { const err = Boom.methodNotAllowed('my message', null, ['GET', 'POST']); expect(err.output.statusCode).to.equal(405); expect(err.output.headers.Allow).to.equal('GET, POST'); }); }); describe('notAcceptable()', () => { it('returns a 406 error statusCode', () => { expect(Boom.notAcceptable().output.statusCode).to.equal(406); }); it('sets the message with the passed in message', () => { expect(Boom.notAcceptable('my message').message).to.equal('my message'); }); }); describe('proxyAuthRequired()', () => { it('returns a 407 error statusCode', () => { expect(Boom.proxyAuthRequired().output.statusCode).to.equal(407); }); it('sets the message with the passed in message', () => { expect(Boom.proxyAuthRequired('my message').message).to.equal('my message'); }); }); describe('clientTimeout()', () => { it('returns a 408 error statusCode', () => { expect(Boom.clientTimeout().output.statusCode).to.equal(408); }); it('sets the message with the passed in message', () => { expect(Boom.clientTimeout('my message').message).to.equal('my message'); }); }); describe('conflict()', () => { it('returns a 409 error statusCode', () => { expect(Boom.conflict().output.statusCode).to.equal(409); }); it('sets the message with the passed in message', () => { expect(Boom.conflict('my message').message).to.equal('my message'); }); }); describe('resourceGone()', () => { it('returns a 410 error statusCode', () => { expect(Boom.resourceGone().output.statusCode).to.equal(410); }); it('sets the message with the passed in message', () => { expect(Boom.resourceGone('my message').message).to.equal('my message'); }); }); describe('lengthRequired()', () => { it('returns a 411 error statusCode', () => { expect(Boom.lengthRequired().output.statusCode).to.equal(411); }); it('sets the message with the passed in message', () => { expect(Boom.lengthRequired('my message').message).to.equal('my message'); }); }); describe('preconditionFailed()', () => { it('returns a 412 error statusCode', () => { expect(Boom.preconditionFailed().output.statusCode).to.equal(412); }); it('sets the message with the passed in message', () => { expect(Boom.preconditionFailed('my message').message).to.equal('my message'); }); }); describe('entityTooLarge()', () => { it('returns a 413 error statusCode', () => { expect(Boom.entityTooLarge().output.statusCode).to.equal(413); }); it('sets the message with the passed in message', () => { expect(Boom.entityTooLarge('my message').message).to.equal('my message'); }); }); describe('uriTooLong()', () => { it('returns a 414 error statusCode', () => { expect(Boom.uriTooLong().output.statusCode).to.equal(414); }); it('sets the message with the passed in message', () => { expect(Boom.uriTooLong('my message').message).to.equal('my message'); }); }); describe('unsupportedMediaType()', () => { it('returns a 415 error statusCode', () => { expect(Boom.unsupportedMediaType().output.statusCode).to.equal(415); }); it('sets the message with the passed in message', () => { expect(Boom.unsupportedMediaType('my message').message).to.equal('my message'); }); }); describe('rangeNotSatisfiable()', () => { it('returns a 416 error statusCode', () => { expect(Boom.rangeNotSatisfiable().output.statusCode).to.equal(416); }); it('sets the message with the passed in message', () => { expect(Boom.rangeNotSatisfiable('my message').message).to.equal('my message'); }); }); describe('expectationFailed()', () => { it('returns a 417 error statusCode', () => { expect(Boom.expectationFailed().output.statusCode).to.equal(417); }); it('sets the message with the passed in message', () => { expect(Boom.expectationFailed('my message').message).to.equal('my message'); }); }); describe('teapot()', () => { it('returns a 418 error statusCode', () => { expect(Boom.teapot().output.statusCode).to.equal(418); }); it('sets the message with the passed in message', () => { expect(Boom.teapot('Sorry, no coffee...').message).to.equal('Sorry, no coffee...'); }); }); describe('badData()', () => { it('returns a 422 error statusCode', () => { expect(Boom.badData().output.statusCode).to.equal(422); }); it('sets the message with the passed in message', () => { expect(Boom.badData('my message').message).to.equal('my message'); }); }); describe('locked()', () => { it('returns a 423 error statusCode', () => { expect(Boom.locked().output.statusCode).to.equal(423); }); it('sets the message with the passed in message', () => { expect(Boom.locked('my message').message).to.equal('my message'); }); }); describe('failedDependency()', () => { it('returns a 424 error statusCode', () => { expect(Boom.failedDependency().output.statusCode).to.equal(424); }); it('sets the message with the passed in message', () => { expect(Boom.failedDependency('my message').message).to.equal('my message'); }); }); describe('tooEarly()', () => { it('returns a 425 error statusCode', () => { expect(Boom.tooEarly().output.statusCode).to.equal(425); }); it('sets the message with the passed in message', () => { expect(Boom.tooEarly('my message').message).to.equal('my message'); }); }); describe('preconditionRequired()', () => { it('returns a 428 error statusCode', () => { expect(Boom.preconditionRequired().output.statusCode).to.equal(428); }); it('sets the message with the passed in message', () => { expect(Boom.preconditionRequired('my message').message).to.equal('my message'); }); }); describe('tooManyRequests()', () => { it('returns a 429 error statusCode', () => { expect(Boom.tooManyRequests().output.statusCode).to.equal(429); }); it('sets the message with the passed-in message', () => { expect(Boom.tooManyRequests('my message').message).to.equal('my message'); }); }); describe('illegal()', () => { it('returns a 451 error statusCode', () => { expect(Boom.illegal().output.statusCode).to.equal(451); }); it('sets the message with the passed-in message', () => { expect(Boom.illegal('my message').message).to.equal('my message'); }); }); describe('serverUnavailable()', () => { it('returns a 503 error statusCode', () => { expect(Boom.serverUnavailable().output.statusCode).to.equal(503); }); it('sets the message with the passed in message', () => { expect(Boom.serverUnavailable('my message').message).to.equal('my message'); }); }); describe('forbidden()', () => { it('returns a 403 error statusCode', () => { expect(Boom.forbidden().output.statusCode).to.equal(403); }); it('sets the message with the passed in message', () => { expect(Boom.forbidden('my message').message).to.equal('my message'); }); }); describe('notFound()', () => { it('returns a 404 error statusCode', () => { expect(Boom.notFound().output.statusCode).to.equal(404); }); it('sets the message with the passed in message', () => { expect(Boom.notFound('my message').message).to.equal('my message'); }); }); describe('internal()', () => { it('returns a 500 error statusCode', () => { expect(Boom.internal().output.statusCode).to.equal(500); }); it('sets the message with the passed in message', () => { const 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'); }); it('passes data on the callback if its passed in', () => { expect(Boom.internal('my message', { my: 'data' }).data.my).to.equal('data'); }); it('returns an error with composite message', () => { const x = {}; try { x.foo(); } catch (err) { const boom = Boom.internal('Someting bad', err); expect(boom.message).to.equal('Someting bad: x.foo is not a function'); expect(boom.isServer).to.be.true(); } }); }); describe('notImplemented()', () => { it('returns a 501 error statusCode', () => { expect(Boom.notImplemented().output.statusCode).to.equal(501); }); it('sets the message with the passed in message', () => { expect(Boom.notImplemented('my message').message).to.equal('my message'); }); }); describe('badGateway()', () => { it('returns a 502 error statusCode', () => { expect(Boom.badGateway().output.statusCode).to.equal(502); }); it('sets the message with the passed in message', () => { expect(Boom.badGateway('my message').message).to.equal('my message'); }); it('retains source boom error as data when wrapped', () => { const upstream = Boom.serverUnavailable(); const boom = Boom.badGateway('Upstream error', upstream); expect(boom.output.statusCode).to.equal(502); expect(boom.data).to.equal(upstream); }); }); describe('gatewayTimeout()', () => { it('returns a 504 error statusCode', () => { expect(Boom.gatewayTimeout().output.statusCode).to.equal(504); }); it('sets the message with the passed in message', () => { expect(Boom.gatewayTimeout('my message').message).to.equal('my message'); }); }); describe('badImplementation()', () => { it('returns a 500 error statusCode', () => { const err = Boom.badImplementation(); expect(err.output.statusCode).to.equal(500); expect(err.isDeveloperError).to.equal(true); expect(err.isServer).to.be.true(); }); it('hides error from user when error data is included', () => { const err = Boom.badImplementation('Invalid', new Error('kaboom')); expect(err.output).to.equal({ headers: {}, statusCode: 500, payload: { error: 'Internal Server Error', message: 'An internal server error occurred', statusCode: 500 } }); }); it('hides error from user when error data is included (boom)', () => { const err = Boom.badImplementation('Invalid', Boom.badRequest('kaboom')); expect(err.isDeveloperError).to.equal(true); expect(err.output).to.equal({ headers: {}, statusCode: 500, payload: { error: 'Internal Server Error', message: 'An internal server error occurred', statusCode: 500 } }); }); }); describe('stack trace', () => { it('should omit lib', () => { ['badRequest', 'unauthorized', 'forbidden', 'notFound', 'methodNotAllowed', 'notAcceptable', 'proxyAuthRequired', 'clientTimeout', 'conflict', 'resourceGone', 'lengthRequired', 'preconditionFailed', 'entityTooLarge', 'uriTooLong', 'unsupportedMediaType', 'rangeNotSatisfiable', 'expectationFailed', 'badData', 'preconditionRequired', 'tooManyRequests', // 500s 'internal', 'notImplemented', 'badGateway', 'serverUnavailable', 'gatewayTimeout', 'badImplementation' ].forEach((name) => { const err = Boom[name](); expect(err.stack).to.not.match(/\/lib\/index\.js/); }); }); }); describe('method with error object instead of message', () => { [ 'badRequest', 'unauthorized', 'forbidden', 'notFound', 'methodNotAllowed', 'notAcceptable', 'proxyAuthRequired', 'clientTimeout', 'conflict', 'resourceGone', 'lengthRequired', 'preconditionFailed', 'entityTooLarge', 'uriTooLong', 'unsupportedMediaType', 'rangeNotSatisfiable', 'expectationFailed', 'badData', 'preconditionRequired', 'tooManyRequests', 'internal', 'notImplemented', 'badGateway', 'serverUnavailable', 'gatewayTimeout', 'badImplementation' ].forEach((name) => { it(`should allow \`Boom${name}(err)\` and preserve the error`, () => { const error = new Error('An example mongoose validation error'); error.name = 'ValidationError'; const err = Boom[name](error); expect(err.name).to.equal('ValidationError'); expect(err.message).to.equal('An example mongoose validation error'); }); // exclude unauthorized if (name !== 'unauthorized') { it(`should allow \`Boom.${name}(err, data)\` and preserve the data`, () => { const error = new Error(); const err = Boom[name](error, { foo: 'bar' }); expect(err.data).to.equal({ foo: 'bar' }); }); } }); }); describe('error.typeof', () => { const types = [ 'badRequest', 'unauthorized', 'forbidden', 'notFound', 'methodNotAllowed', 'notAcceptable', 'proxyAuthRequired', 'clientTimeout', 'conflict', 'resourceGone', 'lengthRequired', 'preconditionFailed', 'entityTooLarge', 'uriTooLong', 'unsupportedMediaType', 'rangeNotSatisfiable', 'expectationFailed', 'badData', 'preconditionRequired', 'tooManyRequests', 'internal', 'notImplemented', 'badGateway', 'serverUnavailable', 'gatewayTimeout', 'badImplementation' ]; types.forEach((name) => { it(`matches typeof Boom.${name}`, () => { const error = Boom[name](); types.forEach((type) => { if (type === name) { expect(error.typeof).to.equal(Boom[name]); } else { expect(error.typeof).to.not.equal(Boom[type]); } }); }); }); }); describe('reformat()', () => { it('displays internal server error messages in debug mode', () => { const error = new Error('ka-boom'); const err = Boom.boomify(error, { statusCode: 500 }); err.reformat(false); expect(err.output).to.equal({ statusCode: 500, payload: { statusCode: 500, error: 'Internal Server Error', message: 'An internal server error occurred' }, headers: {} }); err.reformat(true); expect(err.output).to.equal({ statusCode: 500, payload: { statusCode: 500, error: 'Internal Server Error', message: 'ka-boom' }, headers: {} }); }); it('is redefinable', () => { Object.defineProperty(new Boom.Boom('oops'), 'reformat', { value: true }); }); }); }); boom-10.0.1/test/index.ts000077500000000000000000000363521437175134500152110ustar00rootroot00000000000000import * as Boom from '..'; import * as Lab from '@hapi/lab'; const { expect } = Lab.types; class X { x: number; constructor(value: number) { this.x = value; } }; const decorate = new X(1); // new Boom.Boom() expect.type(new Boom.Boom()); expect.type(new Boom.Boom()); expect.type(new Boom.Boom('error')); expect.error(new Boom.Boom('error', { decorate })); // No support for decoration on constructor class CustomError extends Boom.Boom {} expect.type(new CustomError('Some error')); const boom = new Boom.Boom('some error'); expect.type(boom.output); boom.output.payload.custom_null = null; boom.output.payload.custom_number = 42; boom.output.payload.custom_string = 'foo'; boom.output.payload.custom_boolean = true; boom.output.payload.custom_object = { bar: 42 }; boom.output.headers['header1'] = 'foo'; boom.output.headers['header2'] = ['foo', 'bar']; boom.output.headers['header3'] = 42; boom.output.headers['header4'] = undefined; expect.type(boom.output.payload); expect.type(boom.output.headers); // boomify() const error = new Error('Unexpected input'); expect.type(Boom.boomify(error, { statusCode: 400 })); expect.type(Boom.boomify(error, { statusCode: 400, message: 'Unexpected Input', override: false })); expect.type(Boom.boomify(error, { decorate }).x); expect.error(Boom.boomify(error, { statusCode: '400' })); expect.error(Boom.boomify('error')); expect.error(Boom.boomify(error, { statusCode: 400, message: true })); expect.error(Boom.boomify(error, { statusCode: 400, override: 'false' })); expect.error(Boom.boomify()); expect.error(Boom.boomify(error, { decorate }).y); // isBoom expect.type(Boom.boomify(error).isBoom); // isBoom() expect.type(Boom.isBoom(error)); expect.type(Boom.isBoom(error, 404)); expect.type(Boom.isBoom(Boom.boomify(error))); expect.type(Boom.isBoom('error')); expect.type(Boom.isBoom({ foo: 'bar' })); expect.type(Boom.isBoom({ error: true })); expect.error(Boom.isBoom(error, 'test')); expect.error(Boom.isBoom()); // 4xx Errors // badRequest() expect.type(Boom.badRequest('invalid query', 'some data')); expect.type(Boom.badRequest('invalid query', { foo: 'bar' })); expect.type(Boom.badRequest('invalid query')); expect.type(Boom.badRequest()); expect.error(Boom.badRequest(400)); expect.error(Boom.badRequest({ foo: 'bar' })); // unauthorized() expect.type(Boom.unauthorized('invalid password')); expect.type(Boom.unauthorized('invalid password', 'simple')); expect.type(Boom.unauthorized(null, 'Negotiate', 'VGhpcyBpcyBhIHRlc3QgdG9rZW4=')); expect.type(Boom.unauthorized('invalid password', 'sample', { ttl: 0, cache: null, foo: 'bar' })); expect.type(Boom.unauthorized('invalid password', 'sample', { ttl: 0, cache: null, foo: 'bar' } as Boom.unauthorized.Attributes)); expect.type(Boom.unauthorized()); expect.type(Boom.unauthorized('basic', ['a', 'b', 'c'])); expect.type(Boom.unauthorized('', 'basic')); expect.type(Boom.unauthorized(null, 'basic')); expect.type(Boom.unauthorized('', 'basic').isMissing); expect.type(Boom.unauthorized(null, 'basic').isMissing); expect.error(Boom.unauthorized(401)) expect.error(Boom.unauthorized('invalid password', 500)) expect.error(Boom.unauthorized('invalid password', 'sample', 500)) expect.error(Boom.unauthorized('basic', ['a', 'b', 'c'], 'test')); expect.error(Boom.unauthorized('message', 'basic').isMissing); // paymentRequired() expect.type(Boom.paymentRequired('bandwidth used', 'some data')); expect.type(Boom.paymentRequired('bandwidth used', { foo: 'bar' })); expect.type(Boom.paymentRequired('bandwidth used')); expect.type(Boom.paymentRequired()); expect.error(Boom.paymentRequired(402)); expect.error(Boom.paymentRequired({ foo: 'bar' })); // forbidden() expect.type(Boom.forbidden('try again some time', 'some data')); expect.type(Boom.forbidden('try again some time', { foo: 'bar' })); expect.type(Boom.forbidden('try again some time')); expect.type(Boom.forbidden()); expect.error(Boom.forbidden(403)); expect.error(Boom.forbidden({ foo: 'bar' })); // notFound() expect.type(Boom.notFound('missing', 'some data')); expect.type(Boom.notFound('missing', { foo: 'bar' })); expect.type(Boom.notFound('missing')); expect.type(Boom.notFound()); expect.error(Boom.notFound(404)); expect.error(Boom.notFound({ foo: 'bar' })); // methodNotAllowed() expect.type(Boom.methodNotAllowed('this method is not allowed', 'some data')); expect.type(Boom.methodNotAllowed('this method is not allowed', { foo: 'bar' })); expect.type(Boom.methodNotAllowed('this method is not allowed')); expect.type(Boom.methodNotAllowed()); expect.error(Boom.methodNotAllowed(405)); expect.error(Boom.methodNotAllowed({ foo: 'bar' })); // notAcceptable() expect.type(Boom.notAcceptable('unacceptable', 'some data')); expect.type(Boom.notAcceptable('unacceptable', { foo: 'bar' })); expect.type(Boom.notAcceptable('unacceptable')); expect.type(Boom.notAcceptable()); expect.error(Boom.notAcceptable(406)); expect.error(Boom.notAcceptable({ foo: 'bar' })); // proxyAuthRequired() expect.type(Boom.proxyAuthRequired('auth missing', 'some data')); expect.type(Boom.proxyAuthRequired('auth missing', { foo: 'bar' })); expect.type(Boom.proxyAuthRequired('auth missing')); expect.type(Boom.proxyAuthRequired()); expect.error(Boom.proxyAuthRequired(407)); expect.error(Boom.proxyAuthRequired({ foo: 'bar' })); // clientTimeout() expect.type(Boom.clientTimeout('timed out', 'some data')); expect.type(Boom.clientTimeout('timed out', { foo: 'bar' })); expect.type(Boom.clientTimeout('timed out')); expect.type(Boom.clientTimeout()); expect.error(Boom.clientTimeout(408)); expect.error(Boom.clientTimeout({ foo: 'bar' })); // conflict() expect.type(Boom.conflict('there was a conflict', 'some data')); expect.type(Boom.conflict('there was a conflict', { foo: 'bar' })); expect.type(Boom.conflict('there was a conflict')); expect.type(Boom.conflict()); expect.error(Boom.conflict(409)); expect.error(Boom.conflict({ foo: 'bar' })); // resourceGone() expect.type(Boom.resourceGone('it is gone', 'some data')); expect.type(Boom.resourceGone('it is gone', { foo: 'bar' })); expect.type(Boom.resourceGone('it is gone')); expect.type(Boom.resourceGone()); expect.error(Boom.resourceGone(410)); expect.error(Boom.resourceGone({ foo: 'bar' })); // lengthRequired() expect.type(Boom.lengthRequired('length needed', 'some data')); expect.type(Boom.lengthRequired('length needed', { foo: 'bar' })); expect.type(Boom.lengthRequired('length needed')); expect.type(Boom.lengthRequired()); expect.error(Boom.lengthRequired(411)); expect.error(Boom.lengthRequired({ foo: 'bar' })); // preconditionFailed() expect.type(Boom.preconditionFailed('failed', 'some data')); expect.type(Boom.preconditionFailed('failed', { foo: 'bar' })); expect.type(Boom.preconditionFailed('failed')); expect.type(Boom.preconditionFailed()); expect.error(Boom.preconditionFailed(412)); expect.error(Boom.preconditionFailed({ foo: 'bar' })); // entityTooLarge() expect.type(Boom.entityTooLarge('too big', 'some data')); expect.type(Boom.entityTooLarge('too big', { foo: 'bar' })); expect.type(Boom.entityTooLarge('too big')); expect.type(Boom.entityTooLarge()); expect.error(Boom.entityTooLarge(413)); expect.error(Boom.entityTooLarge({ foo: 'bar' })); // uriTooLong() expect.type(Boom.uriTooLong('uri is too long', 'some data')); expect.type(Boom.uriTooLong('uri is too long', { foo: 'bar' })); expect.type(Boom.uriTooLong('uri is too long')); expect.type(Boom.uriTooLong()); expect.error(Boom.uriTooLong(414)); expect.error(Boom.uriTooLong({ foo: 'bar' })); // unsupportedMediaType() expect.type(Boom.unsupportedMediaType('that media is not supported', 'some data')); expect.type(Boom.unsupportedMediaType('that media is not supported', { foo: 'bar' })); expect.type(Boom.unsupportedMediaType('that media is not supported')); expect.type(Boom.unsupportedMediaType()); expect.error(Boom.unsupportedMediaType(415)); expect.error(Boom.unsupportedMediaType({ foo: 'bar' })); // rangeNotSatisfiable() expect.type(Boom.rangeNotSatisfiable('range not satisfiable', 'some data')); expect.type(Boom.rangeNotSatisfiable('range not satisfiable', { foo: 'bar' })); expect.type(Boom.rangeNotSatisfiable('range not satisfiable')); expect.type(Boom.rangeNotSatisfiable()); expect.error(Boom.rangeNotSatisfiable(416)); expect.error(Boom.rangeNotSatisfiable({ foo: 'bar' })); // expectationFailed() expect.type(Boom.expectationFailed('expected this to work', 'some data')); expect.type(Boom.expectationFailed('expected this to work', { foo: 'bar' })); expect.type(Boom.expectationFailed('expected this to work')); expect.type(Boom.expectationFailed()); expect.error(Boom.expectationFailed(417)); expect.error(Boom.expectationFailed({ foo: 'bar' })); // teapot() expect.type(Boom.teapot('sorry, no coffee...', 'some data')); expect.type(Boom.teapot('sorry, no coffee...', { foo: 'bar' })); expect.type(Boom.teapot('sorry, no coffee...')); expect.type(Boom.teapot()); expect.error(Boom.teapot(418)); expect.error(Boom.teapot({ foo: 'bar' })); // badData() expect.type(Boom.badData('your data is bad and you should feel bad', 'some data')); expect.type(Boom.badData('your data is bad and you should feel bad', { foo: 'bar' })); expect.type(Boom.badData('your data is bad and you should feel bad')); expect.type(Boom.badData()); expect.error(Boom.badData(422)); expect.error(Boom.badData({ foo: 'bar' })); // locked() expect.type(Boom.locked('this resource has been locked', 'some data')); expect.type(Boom.locked('this resource has been locked', { foo: 'bar' })); expect.type(Boom.locked('this resource has been locked')); expect.type(Boom.locked()); expect.error(Boom.locked(423)); expect.error(Boom.locked({ foo: 'bar' })); // failedDependency() expect.type(Boom.failedDependency('an external resource failed', 'some data')); expect.type(Boom.failedDependency('an external resource failed', { foo: 'bar' })); expect.type(Boom.failedDependency('an external resource failed')); expect.type(Boom.failedDependency()); expect.error(Boom.failedDependency(424)); expect.error(Boom.failedDependency({ foo: 'bar' })); // tooEarly() expect.type(Boom.tooEarly('won\'t process your request', 'some data')); expect.type(Boom.tooEarly('won\'t process your request', { foo: 'bar' })); expect.type(Boom.tooEarly('won\'t process your request')); expect.type(Boom.tooEarly()); expect.error(Boom.tooEarly(425)); expect.error(Boom.tooEarly({ foo: 'bar' })); // preconditionRequired() expect.type(Boom.preconditionRequired('you must supple an If-Match header', 'some data')); expect.type(Boom.preconditionRequired('you must supple an If-Match header', { foo: 'bar' })); expect.type(Boom.preconditionRequired('you must supple an If-Match header')); expect.type(Boom.preconditionRequired()); expect.error(Boom.preconditionRequired(428)); expect.error(Boom.preconditionRequired({ foo: 'bar' })); // tooManyRequests() expect.type(Boom.tooManyRequests('you have exceeded your request limit', 'some data')); expect.type(Boom.tooManyRequests('you have exceeded your request limit', { foo: 'bar' })); expect.type(Boom.tooManyRequests('you have exceeded your request limit')); expect.type(Boom.tooManyRequests()); expect.error(Boom.tooManyRequests(414)); expect.error(Boom.tooManyRequests({ foo: 'bar' })); // illegal() expect.type(Boom.illegal('you are not permitted to view this resource for legal reasons', 'some data')); expect.type(Boom.illegal('you are not permitted to view this resource for legal reasons', { foo: 'bar' })); expect.type(Boom.illegal('you are not permitted to view this resource for legal reasons')); expect.type(Boom.illegal()); expect.error(Boom.illegal(451)); expect.error(Boom.illegal({ foo: 'bar' })); // 5xx Errors // internal() expect.type(Boom.internal('terrible implementation', 'some data', 599)); expect.type(Boom.internal('terrible implementation', { foo: 'bar' })); expect.type(Boom.internal('terrible implementation')); expect.type(Boom.internal()); expect.error(Boom.internal(500)); expect.error(Boom.internal({ foo: 'bar' })); // badImplementation() expect.type(Boom.badImplementation('terrible implementation', 'some data')); expect.type(Boom.badImplementation('terrible implementation', { foo: 'bar' })); expect.type(Boom.badImplementation('terrible implementation')); expect.type(Boom.badImplementation()); expect.error(Boom.badImplementation(500)); expect.error(Boom.badImplementation({ foo: 'bar' })); // notImplemented() expect.type(Boom.notImplemented('method not implemented', 'some data')); expect.type(Boom.notImplemented('method not implemented', { foo: 'bar' })); expect.type(Boom.notImplemented('method not implemented')); expect.type(Boom.notImplemented()); expect.error(Boom.notImplemented(501)); expect.error(Boom.notImplemented({ foo: 'bar' })); // badGateway() expect.type(Boom.badGateway('this is a bad gateway', 'some data')); expect.type(Boom.badGateway('this is a bad gateway', { foo: 'bar' })); expect.type(Boom.badGateway('this is a bad gateway')); expect.type(Boom.badGateway()); expect.error(Boom.badGateway(502)); expect.error(Boom.badGateway({ foo: 'bar' })); // serverUnavailable() expect.type(Boom.serverUnavailable('unavailable', 'some data')); expect.type(Boom.serverUnavailable('unavailable', { foo: 'bar' })); expect.type(Boom.serverUnavailable('unavailable')); expect.type(Boom.serverUnavailable()); expect.error(Boom.serverUnavailable(503)); expect.error(Boom.serverUnavailable({ foo: 'bar' })); // gatewayTimeout() expect.type(Boom.gatewayTimeout('gateway timeout', 'some data')); expect.type(Boom.gatewayTimeout('gateway timeout', { foo: 'bar' })); expect.type(Boom.gatewayTimeout('gateway timeout')); expect.type(Boom.gatewayTimeout()); expect.error(Boom.gatewayTimeout(504)); expect.error(Boom.gatewayTimeout({ foo: 'bar' }));