mirror of
https://github.com/DanielnetoDotCom/YouPHPTube
synced 2025-10-06 03:50:04 +02:00
Moving to node_modules folder to make easier to upgrade
trying to move from Bootstrap 3 to Bootstrap 5
This commit is contained in:
parent
047e363a16
commit
d4d042e041
8460 changed files with 1355889 additions and 547977 deletions
549
node_modules/@hapi/boom/lib/index.d.ts
generated
vendored
Normal file
549
node_modules/@hapi/boom/lib/index.d.ts
generated
vendored
Normal file
|
@ -0,0 +1,549 @@
|
|||
/**
|
||||
* An Error object used to return an HTTP response error (4xx, 5xx)
|
||||
*/
|
||||
export class Boom<Data = any> extends Error {
|
||||
|
||||
/**
|
||||
* Creates a new Boom object using the provided message
|
||||
*/
|
||||
constructor(message?: string | Error, options?: Options<Data>);
|
||||
|
||||
/**
|
||||
* 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<Data> {
|
||||
/**
|
||||
* 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<Decoration> {
|
||||
|
||||
/**
|
||||
* 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<Data, Decoration>(err: Error, options?: Options<Data> & Decorate<Decoration>): Boom<Data> & Decoration;
|
||||
|
||||
|
||||
// 4xx Errors
|
||||
|
||||
/**
|
||||
* Returns a 400 Bad Request error
|
||||
*
|
||||
* @param message - Optional message
|
||||
* @param data - Optional additional error data
|
||||
*
|
||||
* @returns A 400 bad request error
|
||||
*/
|
||||
export function badRequest<Data>(message?: string, data?: Data): Boom<Data>;
|
||||
|
||||
|
||||
/**
|
||||
* Returns a 401 Unauthorized error
|
||||
*
|
||||
* @param message - Optional message
|
||||
*
|
||||
* @returns A 401 Unauthorized error
|
||||
*/
|
||||
export function unauthorized<Data>(message?: string | null): Boom<Data>;
|
||||
|
||||
|
||||
/**
|
||||
* 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<Data>(message: '' | null, scheme: string, attributes?: string | unauthorized.Attributes): Boom<Data> & unauthorized.MissingAuth;
|
||||
export function unauthorized<Data>(message: string | null, scheme: string, attributes?: string | unauthorized.Attributes): Boom<Data>;
|
||||
|
||||
|
||||
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<Data>(message: string | null, wwwAuthenticate: string[]): Boom<Data>;
|
||||
|
||||
|
||||
/**
|
||||
* Returns a 402 Payment Required error
|
||||
*
|
||||
* @param message - Optional message
|
||||
* @param data - Optional additional error data
|
||||
*
|
||||
* @returns A 402 Payment Required error
|
||||
*/
|
||||
export function paymentRequired<Data>(message?: string, data?: Data): Boom<Data>;
|
||||
|
||||
|
||||
/**
|
||||
* Returns a 403 Forbidden error
|
||||
*
|
||||
* @param message - Optional message
|
||||
* @param data - Optional additional error data
|
||||
*
|
||||
* @returns A 403 Forbidden error
|
||||
*/
|
||||
export function forbidden<Data>(message?: string, data?: Data): Boom<Data>;
|
||||
|
||||
|
||||
/**
|
||||
* Returns a 404 Not Found error
|
||||
*
|
||||
* @param message - Optional message
|
||||
* @param data - Optional additional error data
|
||||
*
|
||||
* @returns A 404 Not Found error
|
||||
*/
|
||||
export function notFound<Data>(message?: string, data?: Data): Boom<Data>;
|
||||
|
||||
|
||||
/**
|
||||
* Returns a 405 Method Not Allowed error
|
||||
*
|
||||
* @param message - Optional message
|
||||
* @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<Data>(message?: string, data?: Data, allow?: string | string[]): Boom<Data>;
|
||||
|
||||
|
||||
/**
|
||||
* Returns a 406 Not Acceptable error
|
||||
*
|
||||
* @param message - Optional message
|
||||
* @param data - Optional additional error data
|
||||
*
|
||||
* @returns A 406 Not Acceptable error
|
||||
*/
|
||||
export function notAcceptable<Data>(message?: string, data?: Data): Boom<Data>;
|
||||
|
||||
|
||||
/**
|
||||
* Returns a 407 Proxy Authentication error
|
||||
*
|
||||
* @param message - Optional message
|
||||
* @param data - Optional additional error data
|
||||
*
|
||||
* @returns A 407 Proxy Authentication error
|
||||
*/
|
||||
export function proxyAuthRequired<Data>(message?: string, data?: Data): Boom<Data>;
|
||||
|
||||
|
||||
/**
|
||||
* Returns a 408 Request Time-out error
|
||||
*
|
||||
* @param message - Optional message
|
||||
* @param data - Optional additional error data
|
||||
*
|
||||
* @returns A 408 Request Time-out error
|
||||
*/
|
||||
export function clientTimeout<Data>(message?: string, data?: Data): Boom<Data>;
|
||||
|
||||
|
||||
/**
|
||||
* Returns a 409 Conflict error
|
||||
*
|
||||
* @param message - Optional message
|
||||
* @param data - Optional additional error data
|
||||
*
|
||||
* @returns A 409 Conflict error
|
||||
*/
|
||||
export function conflict<Data>(message?: string, data?: Data): Boom<Data>;
|
||||
|
||||
|
||||
/**
|
||||
* Returns a 410 Gone error
|
||||
*
|
||||
* @param message - Optional message
|
||||
* @param data - Optional additional error data
|
||||
*
|
||||
* @returns A 410 gone error
|
||||
*/
|
||||
export function resourceGone<Data>(message?: string, data?: Data): Boom<Data>;
|
||||
|
||||
|
||||
/**
|
||||
* Returns a 411 Length Required error
|
||||
*
|
||||
* @param message - Optional message
|
||||
* @param data - Optional additional error data
|
||||
*
|
||||
* @returns A 411 Length Required error
|
||||
*/
|
||||
export function lengthRequired<Data>(message?: string, data?: Data): Boom<Data>;
|
||||
|
||||
|
||||
/**
|
||||
* Returns a 412 Precondition Failed error
|
||||
*
|
||||
* @param message - Optional message
|
||||
* @param data - Optional additional error data
|
||||
*
|
||||
* @returns A 412 Precondition Failed error
|
||||
*/
|
||||
export function preconditionFailed<Data>(message?: string, data?: Data): Boom<Data>;
|
||||
|
||||
|
||||
/**
|
||||
* Returns a 413 Request Entity Too Large error
|
||||
*
|
||||
* @param message - Optional message
|
||||
* @param data - Optional additional error data
|
||||
*
|
||||
* @returns A 413 Request Entity Too Large error
|
||||
*/
|
||||
export function entityTooLarge<Data>(message?: string, data?: Data): Boom<Data>;
|
||||
|
||||
|
||||
/**
|
||||
* Returns a 414 Request-URI Too Large error
|
||||
*
|
||||
* @param message - Optional message
|
||||
* @param data - Optional additional error data
|
||||
*
|
||||
* @returns A 414 Request-URI Too Large error
|
||||
*/
|
||||
export function uriTooLong<Data>(message?: string, data?: Data): Boom<Data>;
|
||||
|
||||
|
||||
/**
|
||||
* Returns a 415 Unsupported Media Type error
|
||||
*
|
||||
* @param message - Optional message
|
||||
* @param data - Optional additional error data
|
||||
*
|
||||
* @returns A 415 Unsupported Media Type error
|
||||
*/
|
||||
export function unsupportedMediaType<Data>(message?: string, data?: Data): Boom<Data>;
|
||||
|
||||
|
||||
/**
|
||||
* Returns a 416 Request Range Not Satisfiable error
|
||||
*
|
||||
* @param message - Optional message
|
||||
* @param data - Optional additional error data
|
||||
*
|
||||
* @returns A 416 Request Range Not Satisfiable error
|
||||
*/
|
||||
export function rangeNotSatisfiable<Data>(message?: string, data?: Data): Boom<Data>;
|
||||
|
||||
|
||||
/**
|
||||
* Returns a 417 Expectation Failed error
|
||||
*
|
||||
* @param message - Optional message
|
||||
* @param data - Optional additional error data
|
||||
*
|
||||
* @returns A 417 Expectation Failed error
|
||||
*/
|
||||
export function expectationFailed<Data>(message?: string, data?: Data): Boom<Data>;
|
||||
|
||||
|
||||
/**
|
||||
* Returns a 418 I'm a Teapot error
|
||||
*
|
||||
* @param message - Optional message
|
||||
* @param data - Optional additional error data
|
||||
*
|
||||
* @returns A 418 I'm a Teapot error
|
||||
*/
|
||||
export function teapot<Data>(message?: string, data?: Data): Boom<Data>;
|
||||
|
||||
|
||||
/**
|
||||
* Returns a 422 Unprocessable Entity error
|
||||
*
|
||||
* @param message - Optional message
|
||||
* @param data - Optional additional error data
|
||||
*
|
||||
* @returns A 422 Unprocessable Entity error
|
||||
*/
|
||||
export function badData<Data>(message?: string, data?: Data): Boom<Data>;
|
||||
|
||||
|
||||
/**
|
||||
* Returns a 423 Locked error
|
||||
*
|
||||
* @param message - Optional message
|
||||
* @param data - Optional additional error data
|
||||
*
|
||||
* @returns A 423 Locked error
|
||||
*/
|
||||
export function locked<Data>(message?: string, data?: Data): Boom<Data>;
|
||||
|
||||
|
||||
/**
|
||||
* Returns a 424 Failed Dependency error
|
||||
*
|
||||
* @param message - Optional message
|
||||
* @param data - Optional additional error data
|
||||
*
|
||||
* @returns A 424 Failed Dependency error
|
||||
*/
|
||||
export function failedDependency<Data>(message?: string, data?: Data): Boom<Data>;
|
||||
|
||||
/**
|
||||
* Returns a 425 Too Early error
|
||||
*
|
||||
* @param message - Optional message
|
||||
* @param data - Optional additional error data
|
||||
*
|
||||
* @returns A 425 Too Early error
|
||||
*/
|
||||
export function tooEarly<Data>(message?: string, data?: Data): Boom<Data>;
|
||||
|
||||
|
||||
/**
|
||||
* Returns a 428 Precondition Required error
|
||||
*
|
||||
* @param message - Optional message
|
||||
* @param data - Optional additional error data
|
||||
*
|
||||
* @returns A 428 Precondition Required error
|
||||
*/
|
||||
export function preconditionRequired<Data>(message?: string, data?: Data): Boom<Data>;
|
||||
|
||||
|
||||
/**
|
||||
* Returns a 429 Too Many Requests error
|
||||
*
|
||||
* @param message - Optional message
|
||||
* @param data - Optional additional error data
|
||||
*
|
||||
* @returns A 429 Too Many Requests error
|
||||
*/
|
||||
export function tooManyRequests<Data>(message?: string, data?: Data): Boom<Data>;
|
||||
|
||||
|
||||
/**
|
||||
* Returns a 451 Unavailable For Legal Reasons error
|
||||
*
|
||||
* @param message - Optional message
|
||||
* @param data - Optional additional error data
|
||||
*
|
||||
* @returns A 451 Unavailable for Legal Reasons error
|
||||
*/
|
||||
export function illegal<Data>(message?: string, data?: Data): Boom<Data>;
|
||||
|
||||
|
||||
// 5xx Errors
|
||||
|
||||
/**
|
||||
* Returns a internal error (defaults to 500)
|
||||
*
|
||||
* @param message - Optional message
|
||||
* @param data - Optional additional error data
|
||||
* @param statusCode - Optional status code override. Defaults to 500.
|
||||
*
|
||||
* @returns A 500 Internal Server error
|
||||
*/
|
||||
export function internal<Data>(message?: string, data?: Data, statusCode?: number): Boom<Data>;
|
||||
|
||||
|
||||
/**
|
||||
* Returns a 500 Internal Server Error error
|
||||
*
|
||||
* @param message - Optional message
|
||||
* @param data - Optional additional error data
|
||||
*
|
||||
* @returns A 500 Internal Server error
|
||||
*/
|
||||
export function badImplementation<Data>(message?: string, data?: Data): Boom<Data>;
|
||||
|
||||
|
||||
/**
|
||||
* Returns a 501 Not Implemented error
|
||||
*
|
||||
* @param message - Optional message
|
||||
* @param data - Optional additional error data
|
||||
*
|
||||
* @returns A 501 Not Implemented error
|
||||
*/
|
||||
export function notImplemented<Data>(message?: string, data?: Data): Boom<Data>;
|
||||
|
||||
|
||||
/**
|
||||
* Returns a 502 Bad Gateway error
|
||||
*
|
||||
* @param message - Optional message
|
||||
* @param data - Optional additional error data
|
||||
*
|
||||
* @returns A 502 Bad Gateway error
|
||||
*/
|
||||
export function badGateway<Data>(message?: string, data?: Data): Boom<Data>;
|
||||
|
||||
|
||||
/**
|
||||
* Returns a 503 Service Unavailable error
|
||||
*
|
||||
* @param message - Optional message
|
||||
* @param data - Optional additional error data
|
||||
*
|
||||
* @returns A 503 Service Unavailable error
|
||||
*/
|
||||
export function serverUnavailable<Data>(message?: string, data?: Data): Boom<Data>;
|
||||
|
||||
|
||||
/**
|
||||
* Returns a 504 Gateway Time-out error
|
||||
*
|
||||
* @param message - Optional message
|
||||
* @param data - Optional additional error data
|
||||
*
|
||||
* @returns A 504 Gateway Time-out error
|
||||
*/
|
||||
export function gatewayTimeout<Data>(message?: string, data?: Data): Boom<Data>;
|
469
node_modules/@hapi/boom/lib/index.js
generated
vendored
Normal file
469
node_modules/@hapi/boom/lib/index.js
generated
vendored
Normal file
|
@ -0,0 +1,469 @@
|
|||
'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(message, options = {}) {
|
||||
|
||||
if (message instanceof Error) {
|
||||
return exports.boomify(Hoek.clone(message), options);
|
||||
}
|
||||
|
||||
const { statusCode = 500, data = null, ctor = exports.Boom } = options;
|
||||
const error = new Error(message ? message : undefined); // Avoids settings null message
|
||||
Error.captureStackTrace(error, ctor); // Filter the stack to our external API
|
||||
error.data = data;
|
||||
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 (message, data) {
|
||||
|
||||
return new exports.Boom(message, { 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) => {
|
||||
|
||||
let value = attributes[name];
|
||||
if (value === null ||
|
||||
value === undefined) {
|
||||
|
||||
value = '';
|
||||
}
|
||||
|
||||
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 (message, data) {
|
||||
|
||||
return new exports.Boom(message, { statusCode: 402, data, ctor: exports.paymentRequired });
|
||||
};
|
||||
|
||||
|
||||
exports.forbidden = function (message, data) {
|
||||
|
||||
return new exports.Boom(message, { statusCode: 403, data, ctor: exports.forbidden });
|
||||
};
|
||||
|
||||
|
||||
exports.notFound = function (message, data) {
|
||||
|
||||
return new exports.Boom(message, { statusCode: 404, data, ctor: exports.notFound });
|
||||
};
|
||||
|
||||
|
||||
exports.methodNotAllowed = function (message, data, allow) {
|
||||
|
||||
const err = new exports.Boom(message, { 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 (message, data) {
|
||||
|
||||
return new exports.Boom(message, { statusCode: 406, data, ctor: exports.notAcceptable });
|
||||
};
|
||||
|
||||
|
||||
exports.proxyAuthRequired = function (message, data) {
|
||||
|
||||
return new exports.Boom(message, { statusCode: 407, data, ctor: exports.proxyAuthRequired });
|
||||
};
|
||||
|
||||
|
||||
exports.clientTimeout = function (message, data) {
|
||||
|
||||
return new exports.Boom(message, { statusCode: 408, data, ctor: exports.clientTimeout });
|
||||
};
|
||||
|
||||
|
||||
exports.conflict = function (message, data) {
|
||||
|
||||
return new exports.Boom(message, { statusCode: 409, data, ctor: exports.conflict });
|
||||
};
|
||||
|
||||
|
||||
exports.resourceGone = function (message, data) {
|
||||
|
||||
return new exports.Boom(message, { statusCode: 410, data, ctor: exports.resourceGone });
|
||||
};
|
||||
|
||||
|
||||
exports.lengthRequired = function (message, data) {
|
||||
|
||||
return new exports.Boom(message, { statusCode: 411, data, ctor: exports.lengthRequired });
|
||||
};
|
||||
|
||||
|
||||
exports.preconditionFailed = function (message, data) {
|
||||
|
||||
return new exports.Boom(message, { statusCode: 412, data, ctor: exports.preconditionFailed });
|
||||
};
|
||||
|
||||
|
||||
exports.entityTooLarge = function (message, data) {
|
||||
|
||||
return new exports.Boom(message, { statusCode: 413, data, ctor: exports.entityTooLarge });
|
||||
};
|
||||
|
||||
|
||||
exports.uriTooLong = function (message, data) {
|
||||
|
||||
return new exports.Boom(message, { statusCode: 414, data, ctor: exports.uriTooLong });
|
||||
};
|
||||
|
||||
|
||||
exports.unsupportedMediaType = function (message, data) {
|
||||
|
||||
return new exports.Boom(message, { statusCode: 415, data, ctor: exports.unsupportedMediaType });
|
||||
};
|
||||
|
||||
|
||||
exports.rangeNotSatisfiable = function (message, data) {
|
||||
|
||||
return new exports.Boom(message, { statusCode: 416, data, ctor: exports.rangeNotSatisfiable });
|
||||
};
|
||||
|
||||
|
||||
exports.expectationFailed = function (message, data) {
|
||||
|
||||
return new exports.Boom(message, { statusCode: 417, data, ctor: exports.expectationFailed });
|
||||
};
|
||||
|
||||
|
||||
exports.teapot = function (message, data) {
|
||||
|
||||
return new exports.Boom(message, { statusCode: 418, data, ctor: exports.teapot });
|
||||
};
|
||||
|
||||
|
||||
exports.badData = function (message, data) {
|
||||
|
||||
return new exports.Boom(message, { statusCode: 422, data, ctor: exports.badData });
|
||||
};
|
||||
|
||||
|
||||
exports.locked = function (message, data) {
|
||||
|
||||
return new exports.Boom(message, { statusCode: 423, data, ctor: exports.locked });
|
||||
};
|
||||
|
||||
|
||||
exports.failedDependency = function (message, data) {
|
||||
|
||||
return new exports.Boom(message, { statusCode: 424, data, ctor: exports.failedDependency });
|
||||
};
|
||||
|
||||
exports.tooEarly = function (message, data) {
|
||||
|
||||
return new exports.Boom(message, { statusCode: 425, data, ctor: exports.tooEarly });
|
||||
};
|
||||
|
||||
|
||||
exports.preconditionRequired = function (message, data) {
|
||||
|
||||
return new exports.Boom(message, { statusCode: 428, data, ctor: exports.preconditionRequired });
|
||||
};
|
||||
|
||||
|
||||
exports.tooManyRequests = function (message, data) {
|
||||
|
||||
return new exports.Boom(message, { statusCode: 429, data, ctor: exports.tooManyRequests });
|
||||
};
|
||||
|
||||
|
||||
exports.illegal = function (message, data) {
|
||||
|
||||
return new exports.Boom(message, { 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 (message, data, statusCode, ctor) {
|
||||
|
||||
if (data instanceof Error &&
|
||||
!data.isBoom) {
|
||||
|
||||
return exports.boomify(data, { statusCode, message });
|
||||
}
|
||||
|
||||
return new exports.Boom(message, { statusCode, data, ctor });
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue