mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-03 14:27:04 +00:00
Merge pull request #22558 from TimonVS/master
Update types for Boom 7.1.1
This commit is contained in:
+44
-39
@@ -1,11 +1,10 @@
|
||||
import Boom = require('boom');
|
||||
import * as Hapi from 'hapi';
|
||||
|
||||
// 4xx and data type
|
||||
|
||||
const badRequestError = Boom.badRequest('message', {some: 'data'});
|
||||
badRequestError.data.some;
|
||||
const badRequestError2: Boom.BoomError = Boom.badImplementation('message');
|
||||
const badRequestError2: Boom.Boom = Boom.badImplementation('message');
|
||||
|
||||
const unauthorizedError1 = Boom.unauthorized('message', 'scheme', {some: 'attribute'});
|
||||
unauthorizedError1.output.payload.attributes === { some: 'attribute', error: 'message' };
|
||||
@@ -25,125 +24,131 @@ unauthorizedError4.output.headers === { 'WWW-Authenticate': 'scheme some="attrib
|
||||
|
||||
const paymentRequiredError = Boom.paymentRequired('message', {some: 'data'});
|
||||
paymentRequiredError.data.some;
|
||||
const paymentRequiredError2: Boom.BoomError = Boom.paymentRequired('message');
|
||||
const paymentRequiredError2: Boom.Boom = Boom.paymentRequired('message');
|
||||
|
||||
const forbiddenError = Boom.forbidden('message', {some: 'data'});
|
||||
forbiddenError.data.some;
|
||||
const forbiddenError2: Boom.BoomError = Boom.forbidden('message');
|
||||
const forbiddenError2: Boom.Boom = Boom.forbidden('message');
|
||||
|
||||
const notFoundError = Boom.notFound('message', {some: 'data'});
|
||||
notFoundError.data.some;
|
||||
const notFoundError2: Boom.BoomError = Boom.notFound('message');
|
||||
const notFoundError2: Boom.Boom = Boom.notFound('message');
|
||||
|
||||
const methodNotAllowedError = Boom.methodNotAllowed('message', {some: 'data'});
|
||||
methodNotAllowedError.data.some;
|
||||
const methodNotAllowedError2: Boom.BoomError = Boom.methodNotAllowed('message');
|
||||
const methodNotAllowedError2: Boom.Boom = Boom.methodNotAllowed('message');
|
||||
|
||||
const notAcceptableError = Boom.notAcceptable('message', {some: 'data'});
|
||||
notAcceptableError.data.some;
|
||||
const notAcceptableError2: Boom.BoomError = Boom.notAcceptable('message');
|
||||
const notAcceptableError2: Boom.Boom = Boom.notAcceptable('message');
|
||||
|
||||
const proxyAuthRequiredError = Boom.proxyAuthRequired('message', {some: 'data'});
|
||||
proxyAuthRequiredError.data.some;
|
||||
const proxyAuthRequiredError2: Boom.BoomError = Boom.proxyAuthRequired('message');
|
||||
const proxyAuthRequiredError2: Boom.Boom = Boom.proxyAuthRequired('message');
|
||||
|
||||
const clientTimeoutError = Boom.clientTimeout('message', {some: 'data'});
|
||||
clientTimeoutError.data.some;
|
||||
const clientTimeoutError2: Boom.BoomError = Boom.clientTimeout('message');
|
||||
const clientTimeoutError2: Boom.Boom = Boom.clientTimeout('message');
|
||||
|
||||
const conflictError = Boom.conflict('message', {some: 'data'});
|
||||
conflictError.data.some;
|
||||
|
||||
const resourceGoneError = Boom.resourceGone('message', {some: 'data'});
|
||||
resourceGoneError.data.some;
|
||||
const resourceGoneError2: Boom.BoomError = Boom.resourceGone('message');
|
||||
const resourceGoneError2: Boom.Boom = Boom.resourceGone('message');
|
||||
|
||||
const lengthRequiredError = Boom.lengthRequired('message', {some: 'data'});
|
||||
lengthRequiredError.data.some;
|
||||
const lengthRequiredError2: Boom.BoomError = Boom.lengthRequired('message');
|
||||
const lengthRequiredError2: Boom.Boom = Boom.lengthRequired('message');
|
||||
|
||||
const preconditionFailedError = Boom.preconditionFailed('message', {some: 'data'});
|
||||
preconditionFailedError.data.some;
|
||||
const preconditionFailedError2: Boom.BoomError = Boom.preconditionFailed('message');
|
||||
const preconditionFailedError2: Boom.Boom = Boom.preconditionFailed('message');
|
||||
|
||||
const entityTooLargeError = Boom.entityTooLarge('message', {some: 'data'});
|
||||
entityTooLargeError.data.some;
|
||||
const entityTooLargeError2: Boom.BoomError = Boom.lengthRequired('message');
|
||||
const entityTooLargeError2: Boom.Boom = Boom.lengthRequired('message');
|
||||
|
||||
const uriTooLongError = Boom.uriTooLong('message', {some: 'data'});
|
||||
uriTooLongError.data.some;
|
||||
const uriTooLongError2: Boom.BoomError = Boom.uriTooLong('message');
|
||||
const uriTooLongError2: Boom.Boom = Boom.uriTooLong('message');
|
||||
|
||||
const unsupportedMediaTypeError = Boom.unsupportedMediaType('message', {some: 'data'});
|
||||
unsupportedMediaTypeError.data.some;
|
||||
const unsupportedMediaTypeError2: Boom.BoomError = Boom.unsupportedMediaType('message');
|
||||
const unsupportedMediaTypeError2: Boom.Boom = Boom.unsupportedMediaType('message');
|
||||
|
||||
const rangeNotSatisfiableError = Boom.rangeNotSatisfiable('message', {some: 'data'});
|
||||
rangeNotSatisfiableError.data.some;
|
||||
const rangeNotSatisfiableError2: Boom.BoomError = Boom.rangeNotSatisfiable('message');
|
||||
const rangeNotSatisfiableError2: Boom.Boom = Boom.rangeNotSatisfiable('message');
|
||||
|
||||
const expectationFailedError = Boom.expectationFailed('message', {some: 'data'});
|
||||
expectationFailedError.data.some;
|
||||
const expectationFailedError2: Boom.BoomError = Boom.expectationFailed('message');
|
||||
const expectationFailedError2: Boom.Boom = Boom.expectationFailed('message');
|
||||
|
||||
const teapotError = Boom.teapot('message', {some: 'data'});
|
||||
teapotError.data.some;
|
||||
const teapotError2: Boom.BoomError = Boom.teapot('message');
|
||||
const teapotError2: Boom.Boom = Boom.teapot('message');
|
||||
|
||||
const badDataError = Boom.badData('message', {some: 'data'});
|
||||
badDataError.data.some;
|
||||
const badDataError2: Boom.BoomError = Boom.badData('message');
|
||||
const badDataError2: Boom.Boom = Boom.badData('message');
|
||||
|
||||
const lockedError = Boom.locked('message', {some: 'data'});
|
||||
lockedError.data.some;
|
||||
const lockedError2: Boom.BoomError = Boom.locked('message');
|
||||
const lockedError2: Boom.Boom = Boom.locked('message');
|
||||
|
||||
const preconditionRequiredError = Boom.preconditionRequired('message', {some: 'data'});
|
||||
preconditionRequiredError.data.some;
|
||||
const preconditionRequiredError2: Boom.BoomError = Boom.preconditionRequired('message');
|
||||
const preconditionRequiredError2: Boom.Boom = Boom.preconditionRequired('message');
|
||||
|
||||
const tooManyRequestsError = Boom.tooManyRequests('message', {some: 'data'});
|
||||
tooManyRequestsError.data.some;
|
||||
const tooManyRequestsError2: Boom.BoomError = Boom.tooManyRequests('message');
|
||||
const tooManyRequestsError2: Boom.Boom = Boom.tooManyRequests('message');
|
||||
|
||||
const illegalError = Boom.illegal('message', {some: 'data'});
|
||||
illegalError.data.some;
|
||||
const illegalError2: Boom.BoomError = Boom.illegal('message');
|
||||
const illegalError2: Boom.Boom = Boom.illegal('message');
|
||||
|
||||
// 5xx and data type
|
||||
|
||||
const badImplementationError = Boom.badImplementation('message', {some: 'data'});
|
||||
badImplementationError.data.some;
|
||||
const badImplementationError2: Boom.BoomError = Boom.badImplementation('message');
|
||||
const badImplementationError2: Boom.Boom = Boom.badImplementation('message');
|
||||
|
||||
const internalError = Boom.internal('message', {some: 'data'});
|
||||
internalError.data.some;
|
||||
const internalError2: Boom.BoomError = Boom.internal('message');
|
||||
const internalError2: Boom.Boom = Boom.internal('message');
|
||||
|
||||
const notImplementedError = Boom.notImplemented('message', {some: 'data'});
|
||||
notImplementedError.data.some;
|
||||
const notImplementedError2: Boom.BoomError = Boom.notImplemented('message');
|
||||
const notImplementedError2: Boom.Boom = Boom.notImplemented('message');
|
||||
|
||||
const badGatewayError = Boom.badGateway('message', {some: 'data'});
|
||||
badGatewayError.data.some;
|
||||
const badGatewayError2: Boom.BoomError = Boom.badGateway('message');
|
||||
const badGatewayError2: Boom.Boom = Boom.badGateway('message');
|
||||
|
||||
const serverUnavailableError = Boom.serverUnavailable('message', {some: 'data'});
|
||||
serverUnavailableError.data.some;
|
||||
const serverUnavailableError2: Boom.BoomError = Boom.serverUnavailable('message');
|
||||
const serverUnavailableError2: Boom.Boom = Boom.serverUnavailable('message');
|
||||
|
||||
const gatewayTimeoutError = Boom.gatewayTimeout('message', {some: 'data'});
|
||||
gatewayTimeoutError.data.some;
|
||||
const gatewayTimeoutError2: Boom.BoomError = Boom.gatewayTimeout('message');
|
||||
const gatewayTimeoutError2: Boom.Boom = Boom.gatewayTimeout('message');
|
||||
|
||||
// boomify, wrap, and create
|
||||
const boomifiedError = Boom.boomify(new Error('test'), { statusCode: 400, message: 'some message' })
|
||||
// boomify
|
||||
const boomifiedError = Boom.boomify(new Error('test'), { statusCode: 400, message: 'some message' });
|
||||
|
||||
const wrappedError = Boom.wrap(new Error('test'), 400, 'some message');
|
||||
// isBoom
|
||||
|
||||
const error1 = Boom.create(500, 'Internal server error', { timestamp: Date.now() });
|
||||
error1.data.timestamp;
|
||||
const error2: Boom.BoomError = Boom.create(500, 'Internal server error');
|
||||
const isBoomError = new Boom.Boom('test')
|
||||
|
||||
Boom.isBoom(isBoomError);
|
||||
|
||||
// constructor
|
||||
|
||||
const constructorError: Boom.Boom = new Boom.Boom('test');
|
||||
|
||||
constructorError.message;
|
||||
|
||||
// type widen asserting
|
||||
|
||||
@@ -169,11 +174,11 @@ interface CustomPayload extends Boom.Payload {
|
||||
* Test assignment of custom error data:
|
||||
*/
|
||||
const errorWithData = Boom.badImplementation('', { custom1: 'test', customType: 'Custom1', isCustom: true } as CustomData1);
|
||||
const errorWithNoExplicitDataType: Boom.BoomError = errorWithData; // can assign to error without explicit data type
|
||||
const errorWithExplicitType: Boom.BoomError<CustomData> = errorWithData; // can assign to union data type
|
||||
const errorWithConcreteCustomData: Boom.BoomError<CustomData1> = errorWithData; // can assign to concrete data type
|
||||
const errorWithNoExplicitDataType: Boom.Boom = errorWithData; // can assign to error without explicit data type
|
||||
const errorWithExplicitType: Boom.Boom<CustomData> = errorWithData; // can assign to union data type
|
||||
const errorWithConcreteCustomData: Boom.Boom<CustomData1> = errorWithData; // can assign to concrete data type
|
||||
// assignment to CustomData2 would not be possible
|
||||
// const errorWithConcreteCustomData2: Boom.BoomError<CustomData2> = errorWithData;
|
||||
// const errorWithConcreteCustomData2: Boom.Boom<CustomData2> = errorWithData;
|
||||
|
||||
// Some complex error data types for testing purposes:
|
||||
interface CustomDataBase {
|
||||
|
||||
Vendored
+57
-51
@@ -1,8 +1,9 @@
|
||||
// Type definitions for boom 4.3
|
||||
// Type definitions for boom 7.1.1
|
||||
// Project: https://github.com/hapijs/boom
|
||||
// Definitions by: Igor Rogatty <https://github.com/rogatty>
|
||||
// AJP <https://github.com/AJamesPhillips>
|
||||
// Jinesh Shah <https://github.com/jineshshah36>
|
||||
// Timon van Spronsen <https://github.com/TimonVS>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.4
|
||||
|
||||
@@ -14,7 +15,9 @@ declare namespace Boom {
|
||||
* boom provides a set of utilities for returning HTTP errors. Each utility returns a Boom error response object (instance of Error) which includes the following properties:
|
||||
* @see {@link https://github.com/hapijs/boom#boom}
|
||||
*/
|
||||
export interface BoomError<Data = any> extends Error {
|
||||
export class Boom<Data = any> extends Error {
|
||||
/** Creates a new Boom object using the provided message and then calling boomify() to decorate the error with the Boom properties. */
|
||||
constructor(message?: string | Error, options?: Options<Data>);
|
||||
/** isBoom - if true, indicates this is a Boom object instance. */
|
||||
isBoom: boolean;
|
||||
/** isServer - convenience bool indicating status code >= 500. */
|
||||
@@ -31,6 +34,21 @@ declare namespace Boom {
|
||||
data: Data;
|
||||
}
|
||||
|
||||
interface Options<Data> {
|
||||
/** statusCode - the HTTP status code. Defaults to 500 if no status code is already set. */
|
||||
statusCode?: number;
|
||||
/** data - additional error information (assigned to error.data). */
|
||||
data?: Data;
|
||||
/** decorate - an option with extra properties to set on the error object. */
|
||||
decorate?: object;
|
||||
/** ctor - constructor reference used to crop the exception call stack output. */
|
||||
ctor?: any;
|
||||
/** message - error message string. If the error already has a message, the provided message is added as a prefix. Defaults to no message. */
|
||||
message?: string;
|
||||
/** 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). */
|
||||
override?: boolean;
|
||||
}
|
||||
|
||||
export interface Output {
|
||||
/** statusCode - the HTTP status code (typically 4xx or 5xx). */
|
||||
statusCode: number;
|
||||
@@ -62,25 +80,13 @@ declare namespace Boom {
|
||||
* @param options optional additional options
|
||||
* @see {@link https://github.com/hapijs/boom#boomifyerror-options}
|
||||
*/
|
||||
export function boomify(error: Error, options?: { statusCode?: number, message?: string, override?: boolean }): BoomError<null>;
|
||||
export function boomify(error: Error, options?: { statusCode?: number, message?: string, override?: boolean }): Boom<null>;
|
||||
|
||||
/**
|
||||
* Decorates an error with the boom properties
|
||||
* @param error the error object to wrap. If error is already a boom object, returns back the same object.
|
||||
* @param statusCode optional HTTP status code. Defaults to 500.
|
||||
* @param message optional message string. If the error already has a message, it adds the message as a prefix. Defaults to no message.
|
||||
* @see {@link https://github.com/hapijs/boom#wraperror-statuscode-message}
|
||||
* Identifies whether an error is a Boom object. Same as calling instanceof Boom.
|
||||
* @param error the error object to identify.
|
||||
*/
|
||||
export function wrap(error: Error, statusCode?: number, message?: string): BoomError<null>;
|
||||
|
||||
/**
|
||||
* Generates an Error object with the boom decorations
|
||||
* @param statusCode an HTTP error code number. Must be greater or equal 400.
|
||||
* @param message optional message string.
|
||||
* @param data additional error data set to error.data property.
|
||||
* @see {@link https://github.com/hapijs/boom#createstatuscode-message-data}
|
||||
*/
|
||||
export function create<Data = null>(statusCode: number, message?: string, data?: Data): BoomError<Data>;
|
||||
export function isBoom(error: Error): boolean
|
||||
|
||||
// 4xx
|
||||
/**
|
||||
@@ -89,7 +95,7 @@ declare namespace Boom {
|
||||
* @param data optional additional error data.
|
||||
* @see {@link https://github.com/hapijs/boom#boombadrequestmessage-data}
|
||||
*/
|
||||
export function badRequest<Data = null>(message?: string, data?: Data): BoomError<Data>;
|
||||
export function badRequest<Data = null>(message?: string, data?: Data): Boom<Data>;
|
||||
|
||||
/**
|
||||
* Returns a 401 Unauthorized error
|
||||
@@ -100,10 +106,10 @@ declare namespace Boom {
|
||||
* @param 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.
|
||||
* @see {@link https://github.com/hapijs/boom#boomunauthorizedmessage-scheme-attributes}
|
||||
*/
|
||||
export function unauthorized(message?: string, scheme?: string, attributes?: {[index: string]: string}): BoomError<null>;
|
||||
export function unauthorized(message?: string, scheme?: string[]): BoomError<null>;
|
||||
export function unauthorized(message?: null, scheme?: string, attributes?: {[index: string]: string} | string): BoomError<null>;
|
||||
export function unauthorized(message?: null, scheme?: string[]): BoomError<null>;
|
||||
export function unauthorized(message?: string, scheme?: string, attributes?: {[index: string]: string}): Boom<null>;
|
||||
export function unauthorized(message?: string, scheme?: string[]): Boom<null>;
|
||||
export function unauthorized(message?: null, scheme?: string, attributes?: {[index: string]: string} | string): Boom<null>;
|
||||
export function unauthorized(message?: null, scheme?: string[]): Boom<null>;
|
||||
|
||||
/**
|
||||
* Returns a 402 Payment Required error
|
||||
@@ -111,7 +117,7 @@ declare namespace Boom {
|
||||
* @param data optional additional error data.
|
||||
* @see {@link https://github.com/hapijs/boom#boompaymentrequiredmessage-data}
|
||||
*/
|
||||
export function paymentRequired<Data = null>(message?: string, data?: Data): BoomError<Data>;
|
||||
export function paymentRequired<Data = null>(message?: string, data?: Data): Boom<Data>;
|
||||
|
||||
/**
|
||||
* Returns a 403 Forbidden error
|
||||
@@ -119,7 +125,7 @@ declare namespace Boom {
|
||||
* @param data optional additional error data.
|
||||
* @see {@link https://github.com/hapijs/boom#boomforbiddenmessage-data}
|
||||
*/
|
||||
export function forbidden<Data = null>(message?: string, data?: Data): BoomError<Data>;
|
||||
export function forbidden<Data = null>(message?: string, data?: Data): Boom<Data>;
|
||||
|
||||
/**
|
||||
* Returns a 404 Not Found error
|
||||
@@ -127,7 +133,7 @@ declare namespace Boom {
|
||||
* @param data optional additional error data.
|
||||
* @see {@link https://github.com/hapijs/boom#boomnotfoundmessage-data}
|
||||
*/
|
||||
export function notFound<Data = null>(message?: string, data?: Data): BoomError<Data>;
|
||||
export function notFound<Data = null>(message?: string, data?: Data): Boom<Data>;
|
||||
|
||||
/**
|
||||
* Returns a 405 Method Not Allowed error
|
||||
@@ -136,7 +142,7 @@ declare namespace Boom {
|
||||
* @param allow optional string or array of strings (to be combined and separated by ', ') which is set to the 'Allow' header.
|
||||
* @see {@link https://github.com/hapijs/boom#boommethodnotallowedmessage-data-allow}
|
||||
*/
|
||||
export function methodNotAllowed<Data = null>(message?: string, data?: Data, allow?: string | string[]): BoomError<Data>;
|
||||
export function methodNotAllowed<Data = null>(message?: string, data?: Data, allow?: string | string[]): Boom<Data>;
|
||||
|
||||
/**
|
||||
* Returns a 406 Not Acceptable error
|
||||
@@ -144,7 +150,7 @@ declare namespace Boom {
|
||||
* @param data optional additional error data.
|
||||
* @see {@link https://github.com/hapijs/boom#boomnotacceptablemessage-data}
|
||||
*/
|
||||
export function notAcceptable<Data = null>(message?: string, data?: Data): BoomError<Data>;
|
||||
export function notAcceptable<Data = null>(message?: string, data?: Data): Boom<Data>;
|
||||
|
||||
/**
|
||||
* Returns a 407 Proxy Authentication Required error
|
||||
@@ -152,7 +158,7 @@ declare namespace Boom {
|
||||
* @param data optional additional error data.
|
||||
* @see {@link https://github.com/hapijs/boom#boomproxyauthrequiredmessage-data}
|
||||
*/
|
||||
export function proxyAuthRequired<Data = null>(message?: string, data?: Data): BoomError<Data>;
|
||||
export function proxyAuthRequired<Data = null>(message?: string, data?: Data): Boom<Data>;
|
||||
|
||||
/**
|
||||
* Returns a 408 Request Time-out error
|
||||
@@ -160,7 +166,7 @@ declare namespace Boom {
|
||||
* @param data optional additional error data.
|
||||
* @see {@link https://github.com/hapijs/boom#boomclienttimeoutmessage-data}
|
||||
*/
|
||||
export function clientTimeout<Data = null>(message?: string, data?: Data): BoomError<Data>;
|
||||
export function clientTimeout<Data = null>(message?: string, data?: Data): Boom<Data>;
|
||||
|
||||
/**
|
||||
* Returns a 409 Conflict error
|
||||
@@ -168,7 +174,7 @@ declare namespace Boom {
|
||||
* @param data optional additional error data.
|
||||
* @see {@link https://github.com/hapijs/boom#boomconflictmessage-data}
|
||||
*/
|
||||
export function conflict<Data = null>(message?: string, data?: Data): BoomError<Data>;
|
||||
export function conflict<Data = null>(message?: string, data?: Data): Boom<Data>;
|
||||
|
||||
/**
|
||||
* Returns a 410 Gone error
|
||||
@@ -176,7 +182,7 @@ declare namespace Boom {
|
||||
* @param data optional additional error data.
|
||||
* @see {@link https://github.com/hapijs/boom#boomresourcegonemessage-data}
|
||||
*/
|
||||
export function resourceGone<Data = null>(message?: string, data?: Data): BoomError<Data>;
|
||||
export function resourceGone<Data = null>(message?: string, data?: Data): Boom<Data>;
|
||||
|
||||
/**
|
||||
* Returns a 411 Length Required error
|
||||
@@ -184,7 +190,7 @@ declare namespace Boom {
|
||||
* @param data optional additional error data.
|
||||
* @see {@link https://github.com/hapijs/boom#boomlengthrequiredmessage-data}
|
||||
*/
|
||||
export function lengthRequired<Data = null>(message?: string, data?: Data): BoomError<Data>;
|
||||
export function lengthRequired<Data = null>(message?: string, data?: Data): Boom<Data>;
|
||||
|
||||
/**
|
||||
* Returns a 412 Precondition Failed error
|
||||
@@ -192,7 +198,7 @@ declare namespace Boom {
|
||||
* @param data optional additional error data.
|
||||
* @see {@link https://github.com/hapijs/boom#boompreconditionfailedmessage-data}
|
||||
*/
|
||||
export function preconditionFailed<Data = null>(message?: string, data?: Data): BoomError<Data>;
|
||||
export function preconditionFailed<Data = null>(message?: string, data?: Data): Boom<Data>;
|
||||
|
||||
/**
|
||||
* Returns a 413 Request Entity Too Large error
|
||||
@@ -200,7 +206,7 @@ declare namespace Boom {
|
||||
* @param data optional additional error data.
|
||||
* @see {@link https://github.com/hapijs/boom#boomentitytoolargemessage-data}
|
||||
*/
|
||||
export function entityTooLarge<Data = null>(message?: string, data?: Data): BoomError<Data>;
|
||||
export function entityTooLarge<Data = null>(message?: string, data?: Data): Boom<Data>;
|
||||
|
||||
/**
|
||||
* Returns a 414 Request-URI Too Large error
|
||||
@@ -208,7 +214,7 @@ declare namespace Boom {
|
||||
* @param data optional additional error data.
|
||||
* @see {@link https://github.com/hapijs/boom#boomuritoolongmessage-data}
|
||||
*/
|
||||
export function uriTooLong<Data = null>(message?: string, data?: Data): BoomError<Data>;
|
||||
export function uriTooLong<Data = null>(message?: string, data?: Data): Boom<Data>;
|
||||
|
||||
/**
|
||||
* Returns a 415 Unsupported Media Type error
|
||||
@@ -216,7 +222,7 @@ declare namespace Boom {
|
||||
* @param data optional additional error data.
|
||||
* @see {@link https://github.com/hapijs/boom#boomunsupportedmediatypemessage-data}
|
||||
*/
|
||||
export function unsupportedMediaType<Data = null>(message?: string, data?: Data): BoomError<Data>;
|
||||
export function unsupportedMediaType<Data = null>(message?: string, data?: Data): Boom<Data>;
|
||||
|
||||
/**
|
||||
* Returns a 416 Requested Range Not Satisfiable error
|
||||
@@ -224,7 +230,7 @@ declare namespace Boom {
|
||||
* @param data optional additional error data.
|
||||
* @see {@link https://github.com/hapijs/boom#boomrangenotsatisfiablemessage-data}
|
||||
*/
|
||||
export function rangeNotSatisfiable<Data = null>(message?: string, data?: Data): BoomError<Data>;
|
||||
export function rangeNotSatisfiable<Data = null>(message?: string, data?: Data): Boom<Data>;
|
||||
|
||||
/**
|
||||
* Returns a 417 Expectation Failed error
|
||||
@@ -232,7 +238,7 @@ declare namespace Boom {
|
||||
* @param data optional additional error data.
|
||||
* @see {@link https://github.com/hapijs/boom#boomexpectationfailedmessage-data}
|
||||
*/
|
||||
export function expectationFailed<Data = null>(message?: string, data?: Data): BoomError<Data>;
|
||||
export function expectationFailed<Data = null>(message?: string, data?: Data): Boom<Data>;
|
||||
|
||||
/**
|
||||
* Returns a 418 I'm a Teapot error
|
||||
@@ -240,7 +246,7 @@ declare namespace Boom {
|
||||
* @param data optional additional error data.
|
||||
* @see {@link https://github.com/hapijs/boom#boomteapotmessage-data}
|
||||
*/
|
||||
export function teapot<Data = null>(message?: string, data?: Data): BoomError<Data>;
|
||||
export function teapot<Data = null>(message?: string, data?: Data): Boom<Data>;
|
||||
|
||||
/**
|
||||
* Returns a 422 Unprocessable Entity error
|
||||
@@ -248,7 +254,7 @@ declare namespace Boom {
|
||||
* @param data optional additional error data.
|
||||
* @see {@link https://github.com/hapijs/boom#boombaddatamessage-data}
|
||||
*/
|
||||
export function badData<Data = null>(message?: string, data?: Data): BoomError<Data>;
|
||||
export function badData<Data = null>(message?: string, data?: Data): Boom<Data>;
|
||||
|
||||
/**
|
||||
* Returns a 423 Locked error
|
||||
@@ -256,7 +262,7 @@ declare namespace Boom {
|
||||
* @param data optional additional error data.
|
||||
* @see {@link https://github.com/hapijs/boom#boomlockedmessage-data}
|
||||
*/
|
||||
export function locked<Data = null>(message?: string, data?: Data): BoomError<Data>;
|
||||
export function locked<Data = null>(message?: string, data?: Data): Boom<Data>;
|
||||
|
||||
/**
|
||||
* Returns a 428 Precondition Required error
|
||||
@@ -264,7 +270,7 @@ declare namespace Boom {
|
||||
* @param data optional additional error data.
|
||||
* @see {@link https://github.com/hapijs/boom#boompreconditionrequiredmessage-data}
|
||||
*/
|
||||
export function preconditionRequired<Data = null>(message?: string, data?: Data): BoomError<Data>;
|
||||
export function preconditionRequired<Data = null>(message?: string, data?: Data): Boom<Data>;
|
||||
|
||||
/**
|
||||
* Returns a 429 Too Many Requests error
|
||||
@@ -272,7 +278,7 @@ declare namespace Boom {
|
||||
* @param data optional additional error data.
|
||||
* @see {@link https://github.com/hapijs/boom#boomtoomanyrequestsmessage-data}
|
||||
*/
|
||||
export function tooManyRequests<Data = null>(message?: string, data?: Data): BoomError<Data>;
|
||||
export function tooManyRequests<Data = null>(message?: string, data?: Data): Boom<Data>;
|
||||
|
||||
/**
|
||||
* Returns a 451 Unavailable For Legal Reasons error
|
||||
@@ -280,7 +286,7 @@ declare namespace Boom {
|
||||
* @param data optional additional error data.
|
||||
* @see {@link https://github.com/hapijs/boom#boomillegalmessage-data}
|
||||
*/
|
||||
export function illegal<Data = null>(message?: string, data?: Data): BoomError<Data>;
|
||||
export function illegal<Data = null>(message?: string, data?: Data): Boom<Data>;
|
||||
|
||||
// 5xx
|
||||
/**
|
||||
@@ -290,7 +296,7 @@ declare namespace Boom {
|
||||
* @param data optional additional error data.
|
||||
* @see {@link https://github.com/hapijs/boom#boombadimplementationmessage-data---alias-internal}
|
||||
*/
|
||||
export function badImplementation<Data = null>(message?: string, data?: Data): BoomError<Data>;
|
||||
export function badImplementation<Data = null>(message?: string, data?: Data): Boom<Data>;
|
||||
|
||||
/**
|
||||
* Returns a 500 Internal Server Error error
|
||||
@@ -299,7 +305,7 @@ declare namespace Boom {
|
||||
* @param data optional additional error data.
|
||||
* @see {@link https://github.com/hapijs/boom#boombadimplementationmessage-data---alias-internal}
|
||||
*/
|
||||
export function internal<Data = null>(message?: string, data?: Data): BoomError<Data>;
|
||||
export function internal<Data = null>(message?: string, data?: Data): Boom<Data>;
|
||||
|
||||
/**
|
||||
* Returns a 501 Not Implemented error with your error message to the user
|
||||
@@ -307,7 +313,7 @@ declare namespace Boom {
|
||||
* @param data optional additional error data.
|
||||
* @see {@link https://github.com/hapijs/boom#boomnotimplementedmessage-data}
|
||||
*/
|
||||
export function notImplemented<Data = null>(message?: string, data?: Data): BoomError<Data>;
|
||||
export function notImplemented<Data = null>(message?: string, data?: Data): Boom<Data>;
|
||||
|
||||
/**
|
||||
* Returns a 502 Bad Gateway error with your error message to the user
|
||||
@@ -315,7 +321,7 @@ declare namespace Boom {
|
||||
* @param data optional additional error data.
|
||||
* @see {@link https://github.com/hapijs/boom#boombadgatewaymessage-data}
|
||||
*/
|
||||
export function badGateway<Data = null>(message?: string, data?: Data): BoomError<Data>;
|
||||
export function badGateway<Data = null>(message?: string, data?: Data): Boom<Data>;
|
||||
|
||||
/**
|
||||
* Returns a 503 Service Unavailable error with your error message to the user
|
||||
@@ -323,7 +329,7 @@ declare namespace Boom {
|
||||
* @param data optional additional error data.
|
||||
* @see {@link https://github.com/hapijs/boom#boomserverunavailablemessage-data}
|
||||
*/
|
||||
export function serverUnavailable<Data = null>(message?: string, data?: Data): BoomError<Data>;
|
||||
export function serverUnavailable<Data = null>(message?: string, data?: Data): Boom<Data>;
|
||||
|
||||
/**
|
||||
* Returns a 504 Gateway Time-out error with your error message to the user
|
||||
@@ -331,5 +337,5 @@ declare namespace Boom {
|
||||
* @param data optional additional error data.
|
||||
* @see {@link https://github.com/hapijs/boom#boomgatewaytimeoutmessage-data}
|
||||
*/
|
||||
export function gatewayTimeout<Data = null>(message?: string, data?: Data): BoomError<Data>;
|
||||
export function gatewayTimeout<Data = null>(message?: string, data?: Data): Boom<Data>;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,193 @@
|
||||
import Boom = require('boom');
|
||||
import * as Hapi from 'hapi';
|
||||
|
||||
// 4xx and data type
|
||||
|
||||
const badRequestError = Boom.badRequest('message', {some: 'data'});
|
||||
badRequestError.data.some;
|
||||
const badRequestError2: Boom.BoomError = Boom.badImplementation('message');
|
||||
|
||||
const unauthorizedError1 = Boom.unauthorized('message', 'scheme', {some: 'attribute'});
|
||||
unauthorizedError1.output.payload.attributes === { some: 'attribute', error: 'message' };
|
||||
unauthorizedError1.output.headers === { 'WWW-Authenticate': 'scheme some="attribute", error="message"' };
|
||||
|
||||
const unauthorizedError2 = Boom.unauthorized('message', ['scheme']);
|
||||
unauthorizedError2.output.payload.attributes === undefined;
|
||||
unauthorizedError2.output.headers === { 'WWW-Authenticate': 'scheme' };
|
||||
|
||||
const unauthorizedError3 = Boom.unauthorized(null, 'scheme', 'attribute');
|
||||
unauthorizedError3.output.payload.attributes === 'attribute';
|
||||
unauthorizedError3.output.headers === { 'WWW-Authenticate': 'scheme attribute' };
|
||||
|
||||
const unauthorizedError4 = Boom.unauthorized(null, 'scheme', {some: 'attribute'});
|
||||
unauthorizedError4.output.payload.attributes === { some: 'attribute' };
|
||||
unauthorizedError4.output.headers === { 'WWW-Authenticate': 'scheme some="attribute"' };
|
||||
|
||||
const paymentRequiredError = Boom.paymentRequired('message', {some: 'data'});
|
||||
paymentRequiredError.data.some;
|
||||
const paymentRequiredError2: Boom.BoomError = Boom.paymentRequired('message');
|
||||
|
||||
const forbiddenError = Boom.forbidden('message', {some: 'data'});
|
||||
forbiddenError.data.some;
|
||||
const forbiddenError2: Boom.BoomError = Boom.forbidden('message');
|
||||
|
||||
const notFoundError = Boom.notFound('message', {some: 'data'});
|
||||
notFoundError.data.some;
|
||||
const notFoundError2: Boom.BoomError = Boom.notFound('message');
|
||||
|
||||
const methodNotAllowedError = Boom.methodNotAllowed('message', {some: 'data'});
|
||||
methodNotAllowedError.data.some;
|
||||
const methodNotAllowedError2: Boom.BoomError = Boom.methodNotAllowed('message');
|
||||
|
||||
const notAcceptableError = Boom.notAcceptable('message', {some: 'data'});
|
||||
notAcceptableError.data.some;
|
||||
const notAcceptableError2: Boom.BoomError = Boom.notAcceptable('message');
|
||||
|
||||
const proxyAuthRequiredError = Boom.proxyAuthRequired('message', {some: 'data'});
|
||||
proxyAuthRequiredError.data.some;
|
||||
const proxyAuthRequiredError2: Boom.BoomError = Boom.proxyAuthRequired('message');
|
||||
|
||||
const clientTimeoutError = Boom.clientTimeout('message', {some: 'data'});
|
||||
clientTimeoutError.data.some;
|
||||
const clientTimeoutError2: Boom.BoomError = Boom.clientTimeout('message');
|
||||
|
||||
const conflictError = Boom.conflict('message', {some: 'data'});
|
||||
conflictError.data.some;
|
||||
|
||||
const resourceGoneError = Boom.resourceGone('message', {some: 'data'});
|
||||
resourceGoneError.data.some;
|
||||
const resourceGoneError2: Boom.BoomError = Boom.resourceGone('message');
|
||||
|
||||
const lengthRequiredError = Boom.lengthRequired('message', {some: 'data'});
|
||||
lengthRequiredError.data.some;
|
||||
const lengthRequiredError2: Boom.BoomError = Boom.lengthRequired('message');
|
||||
|
||||
const preconditionFailedError = Boom.preconditionFailed('message', {some: 'data'});
|
||||
preconditionFailedError.data.some;
|
||||
const preconditionFailedError2: Boom.BoomError = Boom.preconditionFailed('message');
|
||||
|
||||
const entityTooLargeError = Boom.entityTooLarge('message', {some: 'data'});
|
||||
entityTooLargeError.data.some;
|
||||
const entityTooLargeError2: Boom.BoomError = Boom.lengthRequired('message');
|
||||
|
||||
const uriTooLongError = Boom.uriTooLong('message', {some: 'data'});
|
||||
uriTooLongError.data.some;
|
||||
const uriTooLongError2: Boom.BoomError = Boom.uriTooLong('message');
|
||||
|
||||
const unsupportedMediaTypeError = Boom.unsupportedMediaType('message', {some: 'data'});
|
||||
unsupportedMediaTypeError.data.some;
|
||||
const unsupportedMediaTypeError2: Boom.BoomError = Boom.unsupportedMediaType('message');
|
||||
|
||||
const rangeNotSatisfiableError = Boom.rangeNotSatisfiable('message', {some: 'data'});
|
||||
rangeNotSatisfiableError.data.some;
|
||||
const rangeNotSatisfiableError2: Boom.BoomError = Boom.rangeNotSatisfiable('message');
|
||||
|
||||
const expectationFailedError = Boom.expectationFailed('message', {some: 'data'});
|
||||
expectationFailedError.data.some;
|
||||
const expectationFailedError2: Boom.BoomError = Boom.expectationFailed('message');
|
||||
|
||||
const teapotError = Boom.teapot('message', {some: 'data'});
|
||||
teapotError.data.some;
|
||||
const teapotError2: Boom.BoomError = Boom.teapot('message');
|
||||
|
||||
const badDataError = Boom.badData('message', {some: 'data'});
|
||||
badDataError.data.some;
|
||||
const badDataError2: Boom.BoomError = Boom.badData('message');
|
||||
|
||||
const lockedError = Boom.locked('message', {some: 'data'});
|
||||
lockedError.data.some;
|
||||
const lockedError2: Boom.BoomError = Boom.locked('message');
|
||||
|
||||
const preconditionRequiredError = Boom.preconditionRequired('message', {some: 'data'});
|
||||
preconditionRequiredError.data.some;
|
||||
const preconditionRequiredError2: Boom.BoomError = Boom.preconditionRequired('message');
|
||||
|
||||
const tooManyRequestsError = Boom.tooManyRequests('message', {some: 'data'});
|
||||
tooManyRequestsError.data.some;
|
||||
const tooManyRequestsError2: Boom.BoomError = Boom.tooManyRequests('message');
|
||||
|
||||
const illegalError = Boom.illegal('message', {some: 'data'});
|
||||
illegalError.data.some;
|
||||
const illegalError2: Boom.BoomError = Boom.illegal('message');
|
||||
|
||||
// 5xx and data type
|
||||
|
||||
const badImplementationError = Boom.badImplementation('message', {some: 'data'});
|
||||
badImplementationError.data.some;
|
||||
const badImplementationError2: Boom.BoomError = Boom.badImplementation('message');
|
||||
|
||||
const internalError = Boom.internal('message', {some: 'data'});
|
||||
internalError.data.some;
|
||||
const internalError2: Boom.BoomError = Boom.internal('message');
|
||||
|
||||
const notImplementedError = Boom.notImplemented('message', {some: 'data'});
|
||||
notImplementedError.data.some;
|
||||
const notImplementedError2: Boom.BoomError = Boom.notImplemented('message');
|
||||
|
||||
const badGatewayError = Boom.badGateway('message', {some: 'data'});
|
||||
badGatewayError.data.some;
|
||||
const badGatewayError2: Boom.BoomError = Boom.badGateway('message');
|
||||
|
||||
const serverUnavailableError = Boom.serverUnavailable('message', {some: 'data'});
|
||||
serverUnavailableError.data.some;
|
||||
const serverUnavailableError2: Boom.BoomError = Boom.serverUnavailable('message');
|
||||
|
||||
const gatewayTimeoutError = Boom.gatewayTimeout('message', {some: 'data'});
|
||||
gatewayTimeoutError.data.some;
|
||||
const gatewayTimeoutError2: Boom.BoomError = Boom.gatewayTimeout('message');
|
||||
|
||||
// boomify, wrap, and create
|
||||
const boomifiedError = Boom.boomify(new Error('test'), { statusCode: 400, message: 'some message' })
|
||||
|
||||
const wrappedError = Boom.wrap(new Error('test'), 400, 'some message');
|
||||
|
||||
const error1 = Boom.create(500, 'Internal server error', { timestamp: Date.now() });
|
||||
error1.data.timestamp;
|
||||
const error2: Boom.BoomError = Boom.create(500, 'Internal server error');
|
||||
|
||||
// type widen asserting
|
||||
|
||||
const unauthorizedError = Boom.unauthorized() as Error;
|
||||
|
||||
// status code and reformat
|
||||
|
||||
const error = Boom.badRequest('Cannot feed after midnight');
|
||||
error.output.statusCode = 499; // Assign a custom error code
|
||||
error.reformat();
|
||||
|
||||
/**
|
||||
* Add a custom key to the payload
|
||||
*/
|
||||
|
||||
interface CustomPayload extends Boom.Payload {
|
||||
custom: string;
|
||||
}
|
||||
|
||||
(error.output.payload as CustomPayload).custom = 'abc_123';
|
||||
|
||||
/**
|
||||
* Test assignment of custom error data:
|
||||
*/
|
||||
const errorWithData = Boom.badImplementation('', { custom1: 'test', customType: 'Custom1', isCustom: true } as CustomData1);
|
||||
const errorWithNoExplicitDataType: Boom.BoomError = errorWithData; // can assign to error without explicit data type
|
||||
const errorWithExplicitType: Boom.BoomError<CustomData> = errorWithData; // can assign to union data type
|
||||
const errorWithConcreteCustomData: Boom.BoomError<CustomData1> = errorWithData; // can assign to concrete data type
|
||||
// assignment to CustomData2 would not be possible
|
||||
// const errorWithConcreteCustomData2: Boom.BoomError<CustomData2> = errorWithData;
|
||||
|
||||
// Some complex error data types for testing purposes:
|
||||
interface CustomDataBase {
|
||||
isCustom: true;
|
||||
}
|
||||
|
||||
interface CustomData1 extends CustomDataBase {
|
||||
customType: 'Custom1';
|
||||
custom1: string;
|
||||
}
|
||||
|
||||
interface CustomData2 extends CustomDataBase {
|
||||
customType: 'Custom2';
|
||||
custom2: string;
|
||||
}
|
||||
|
||||
type CustomData = CustomData1 | CustomData2;
|
||||
Vendored
+335
@@ -0,0 +1,335 @@
|
||||
// Type definitions for boom 4.3
|
||||
// Project: https://github.com/hapijs/boom
|
||||
// Definitions by: Igor Rogatty <https://github.com/rogatty>
|
||||
// AJP <https://github.com/AJamesPhillips>
|
||||
// Jinesh Shah <https://github.com/jineshshah36>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.4
|
||||
|
||||
export = Boom;
|
||||
|
||||
declare namespace Boom {
|
||||
|
||||
/**
|
||||
* boom provides a set of utilities for returning HTTP errors. Each utility returns a Boom error response object (instance of Error) which includes the following properties:
|
||||
* @see {@link https://github.com/hapijs/boom#boom}
|
||||
*/
|
||||
export interface BoomError<Data = any> extends Error {
|
||||
/** isBoom - if true, indicates this is a Boom object instance. */
|
||||
isBoom: boolean;
|
||||
/** isServer - convenience bool indicating status code >= 500. */
|
||||
isServer: boolean;
|
||||
/** message - the error message. */
|
||||
message: string;
|
||||
/** output - the formatted response. Can be directly manipulated after object construction to return a custom error response. Allowed root keys: */
|
||||
output: Output;
|
||||
/** reformat() - rebuilds error.output using the other object properties. */
|
||||
reformat: () => string;
|
||||
/** "If message is unset, the 'error' segment of the header will not be present and isMissing will be true on the error object." mentioned in @see {@link https://github.com/hapijs/boom#boomunauthorizedmessage-scheme-attributes} */
|
||||
isMissing?: boolean;
|
||||
/** https://github.com/hapijs/boom#createstatuscode-message-data and https://github.com/hapijs/boom/blob/v4.3.0/lib/index.js#L99 */
|
||||
data: Data;
|
||||
}
|
||||
|
||||
export interface Output {
|
||||
/** statusCode - the HTTP status code (typically 4xx or 5xx). */
|
||||
statusCode: number;
|
||||
/** headers - an object containing any HTTP headers where each key is a header name and value is the header content. (Limited value type to string https://github.com/hapijs/boom/issues/151 ) */
|
||||
headers: {[index: string]: string};
|
||||
/** 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: */
|
||||
payload: Payload;
|
||||
}
|
||||
|
||||
export interface Payload {
|
||||
/** statusCode - the HTTP status code, derived from error.output.statusCode. */
|
||||
statusCode: number;
|
||||
/** error - the HTTP status message (e.g. 'Bad Request', 'Internal Server Error') derived from statusCode. */
|
||||
error: string;
|
||||
/** message - the error message derived from error.message. */
|
||||
message: string;
|
||||
/**
|
||||
* "Every key/value pair will be included ... in the response payload under the attributes key."
|
||||
* [see docs](https://github.com/hapijs/boom#boomunauthorizedmessage-scheme-attributes)
|
||||
*/
|
||||
attributes?: any;
|
||||
// Excluded this to aid typing of the other values. See tests for example casting to a custom interface to manipulate the payload
|
||||
// [anyContent: string]: any;
|
||||
}
|
||||
|
||||
/**
|
||||
* Decorates an error with the boom properties
|
||||
* @param error the error object to wrap. If error is already a boom object, it defaults to overriding the object with the new status code and message.
|
||||
* @param options optional additional options
|
||||
* @see {@link https://github.com/hapijs/boom#boomifyerror-options}
|
||||
*/
|
||||
export function boomify(error: Error, options?: { statusCode?: number, message?: string, override?: boolean }): BoomError<null>;
|
||||
|
||||
/**
|
||||
* Decorates an error with the boom properties
|
||||
* @param error the error object to wrap. If error is already a boom object, returns back the same object.
|
||||
* @param statusCode optional HTTP status code. Defaults to 500.
|
||||
* @param message optional message string. If the error already has a message, it adds the message as a prefix. Defaults to no message.
|
||||
* @see {@link https://github.com/hapijs/boom#wraperror-statuscode-message}
|
||||
*/
|
||||
export function wrap(error: Error, statusCode?: number, message?: string): BoomError<null>;
|
||||
|
||||
/**
|
||||
* Generates an Error object with the boom decorations
|
||||
* @param statusCode an HTTP error code number. Must be greater or equal 400.
|
||||
* @param message optional message string.
|
||||
* @param data additional error data set to error.data property.
|
||||
* @see {@link https://github.com/hapijs/boom#createstatuscode-message-data}
|
||||
*/
|
||||
export function create<Data = null>(statusCode: number, message?: string, data?: Data): BoomError<Data>;
|
||||
|
||||
// 4xx
|
||||
/**
|
||||
* Returns a 400 Bad Request error
|
||||
* @param message optional message.
|
||||
* @param data optional additional error data.
|
||||
* @see {@link https://github.com/hapijs/boom#boombadrequestmessage-data}
|
||||
*/
|
||||
export function badRequest<Data = null>(message?: string, data?: Data): BoomError<Data>;
|
||||
|
||||
/**
|
||||
* Returns a 401 Unauthorized error
|
||||
* @param message optional message.
|
||||
* @param 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.
|
||||
* @param 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.
|
||||
* @see {@link https://github.com/hapijs/boom#boomunauthorizedmessage-scheme-attributes}
|
||||
*/
|
||||
export function unauthorized(message?: string, scheme?: string, attributes?: {[index: string]: string}): BoomError<null>;
|
||||
export function unauthorized(message?: string, scheme?: string[]): BoomError<null>;
|
||||
export function unauthorized(message?: null, scheme?: string, attributes?: {[index: string]: string} | string): BoomError<null>;
|
||||
export function unauthorized(message?: null, scheme?: string[]): BoomError<null>;
|
||||
|
||||
/**
|
||||
* Returns a 402 Payment Required error
|
||||
* @param message optional message.
|
||||
* @param data optional additional error data.
|
||||
* @see {@link https://github.com/hapijs/boom#boompaymentrequiredmessage-data}
|
||||
*/
|
||||
export function paymentRequired<Data = null>(message?: string, data?: Data): BoomError<Data>;
|
||||
|
||||
/**
|
||||
* Returns a 403 Forbidden error
|
||||
* @param message optional message.
|
||||
* @param data optional additional error data.
|
||||
* @see {@link https://github.com/hapijs/boom#boomforbiddenmessage-data}
|
||||
*/
|
||||
export function forbidden<Data = null>(message?: string, data?: Data): BoomError<Data>;
|
||||
|
||||
/**
|
||||
* Returns a 404 Not Found error
|
||||
* @param message optional message.
|
||||
* @param data optional additional error data.
|
||||
* @see {@link https://github.com/hapijs/boom#boomnotfoundmessage-data}
|
||||
*/
|
||||
export function notFound<Data = null>(message?: string, data?: Data): BoomError<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 (to be combined and separated by ', ') which is set to the 'Allow' header.
|
||||
* @see {@link https://github.com/hapijs/boom#boommethodnotallowedmessage-data-allow}
|
||||
*/
|
||||
export function methodNotAllowed<Data = null>(message?: string, data?: Data, allow?: string | string[]): BoomError<Data>;
|
||||
|
||||
/**
|
||||
* Returns a 406 Not Acceptable error
|
||||
* @param message optional message.
|
||||
* @param data optional additional error data.
|
||||
* @see {@link https://github.com/hapijs/boom#boomnotacceptablemessage-data}
|
||||
*/
|
||||
export function notAcceptable<Data = null>(message?: string, data?: Data): BoomError<Data>;
|
||||
|
||||
/**
|
||||
* Returns a 407 Proxy Authentication Required error
|
||||
* @param message optional message.
|
||||
* @param data optional additional error data.
|
||||
* @see {@link https://github.com/hapijs/boom#boomproxyauthrequiredmessage-data}
|
||||
*/
|
||||
export function proxyAuthRequired<Data = null>(message?: string, data?: Data): BoomError<Data>;
|
||||
|
||||
/**
|
||||
* Returns a 408 Request Time-out error
|
||||
* @param message optional message.
|
||||
* @param data optional additional error data.
|
||||
* @see {@link https://github.com/hapijs/boom#boomclienttimeoutmessage-data}
|
||||
*/
|
||||
export function clientTimeout<Data = null>(message?: string, data?: Data): BoomError<Data>;
|
||||
|
||||
/**
|
||||
* Returns a 409 Conflict error
|
||||
* @param message optional message.
|
||||
* @param data optional additional error data.
|
||||
* @see {@link https://github.com/hapijs/boom#boomconflictmessage-data}
|
||||
*/
|
||||
export function conflict<Data = null>(message?: string, data?: Data): BoomError<Data>;
|
||||
|
||||
/**
|
||||
* Returns a 410 Gone error
|
||||
* @param message optional message.
|
||||
* @param data optional additional error data.
|
||||
* @see {@link https://github.com/hapijs/boom#boomresourcegonemessage-data}
|
||||
*/
|
||||
export function resourceGone<Data = null>(message?: string, data?: Data): BoomError<Data>;
|
||||
|
||||
/**
|
||||
* Returns a 411 Length Required error
|
||||
* @param message optional message.
|
||||
* @param data optional additional error data.
|
||||
* @see {@link https://github.com/hapijs/boom#boomlengthrequiredmessage-data}
|
||||
*/
|
||||
export function lengthRequired<Data = null>(message?: string, data?: Data): BoomError<Data>;
|
||||
|
||||
/**
|
||||
* Returns a 412 Precondition Failed error
|
||||
* @param message optional message.
|
||||
* @param data optional additional error data.
|
||||
* @see {@link https://github.com/hapijs/boom#boompreconditionfailedmessage-data}
|
||||
*/
|
||||
export function preconditionFailed<Data = null>(message?: string, data?: Data): BoomError<Data>;
|
||||
|
||||
/**
|
||||
* Returns a 413 Request Entity Too Large error
|
||||
* @param message optional message.
|
||||
* @param data optional additional error data.
|
||||
* @see {@link https://github.com/hapijs/boom#boomentitytoolargemessage-data}
|
||||
*/
|
||||
export function entityTooLarge<Data = null>(message?: string, data?: Data): BoomError<Data>;
|
||||
|
||||
/**
|
||||
* Returns a 414 Request-URI Too Large error
|
||||
* @param message optional message.
|
||||
* @param data optional additional error data.
|
||||
* @see {@link https://github.com/hapijs/boom#boomuritoolongmessage-data}
|
||||
*/
|
||||
export function uriTooLong<Data = null>(message?: string, data?: Data): BoomError<Data>;
|
||||
|
||||
/**
|
||||
* Returns a 415 Unsupported Media Type error
|
||||
* @param message optional message.
|
||||
* @param data optional additional error data.
|
||||
* @see {@link https://github.com/hapijs/boom#boomunsupportedmediatypemessage-data}
|
||||
*/
|
||||
export function unsupportedMediaType<Data = null>(message?: string, data?: Data): BoomError<Data>;
|
||||
|
||||
/**
|
||||
* Returns a 416 Requested Range Not Satisfiable error
|
||||
* @param message optional message.
|
||||
* @param data optional additional error data.
|
||||
* @see {@link https://github.com/hapijs/boom#boomrangenotsatisfiablemessage-data}
|
||||
*/
|
||||
export function rangeNotSatisfiable<Data = null>(message?: string, data?: Data): BoomError<Data>;
|
||||
|
||||
/**
|
||||
* Returns a 417 Expectation Failed error
|
||||
* @param message optional message.
|
||||
* @param data optional additional error data.
|
||||
* @see {@link https://github.com/hapijs/boom#boomexpectationfailedmessage-data}
|
||||
*/
|
||||
export function expectationFailed<Data = null>(message?: string, data?: Data): BoomError<Data>;
|
||||
|
||||
/**
|
||||
* Returns a 418 I'm a Teapot error
|
||||
* @param message optional message.
|
||||
* @param data optional additional error data.
|
||||
* @see {@link https://github.com/hapijs/boom#boomteapotmessage-data}
|
||||
*/
|
||||
export function teapot<Data = null>(message?: string, data?: Data): BoomError<Data>;
|
||||
|
||||
/**
|
||||
* Returns a 422 Unprocessable Entity error
|
||||
* @param message optional message.
|
||||
* @param data optional additional error data.
|
||||
* @see {@link https://github.com/hapijs/boom#boombaddatamessage-data}
|
||||
*/
|
||||
export function badData<Data = null>(message?: string, data?: Data): BoomError<Data>;
|
||||
|
||||
/**
|
||||
* Returns a 423 Locked error
|
||||
* @param message optional message.
|
||||
* @param data optional additional error data.
|
||||
* @see {@link https://github.com/hapijs/boom#boomlockedmessage-data}
|
||||
*/
|
||||
export function locked<Data = null>(message?: string, data?: Data): BoomError<Data>;
|
||||
|
||||
/**
|
||||
* Returns a 428 Precondition Required error
|
||||
* @param message optional message.
|
||||
* @param data optional additional error data.
|
||||
* @see {@link https://github.com/hapijs/boom#boompreconditionrequiredmessage-data}
|
||||
*/
|
||||
export function preconditionRequired<Data = null>(message?: string, data?: Data): BoomError<Data>;
|
||||
|
||||
/**
|
||||
* Returns a 429 Too Many Requests error
|
||||
* @param message optional message.
|
||||
* @param data optional additional error data.
|
||||
* @see {@link https://github.com/hapijs/boom#boomtoomanyrequestsmessage-data}
|
||||
*/
|
||||
export function tooManyRequests<Data = null>(message?: string, data?: Data): BoomError<Data>;
|
||||
|
||||
/**
|
||||
* Returns a 451 Unavailable For Legal Reasons error
|
||||
* @param message optional message.
|
||||
* @param data optional additional error data.
|
||||
* @see {@link https://github.com/hapijs/boom#boomillegalmessage-data}
|
||||
*/
|
||||
export function illegal<Data = null>(message?: string, data?: Data): BoomError<Data>;
|
||||
|
||||
// 5xx
|
||||
/**
|
||||
* Returns a 500 Internal Server Error error
|
||||
* Only 500 errors will hide your message from the end user. Your message is recorded in the server log.
|
||||
* @param message optional message.
|
||||
* @param data optional additional error data.
|
||||
* @see {@link https://github.com/hapijs/boom#boombadimplementationmessage-data---alias-internal}
|
||||
*/
|
||||
export function badImplementation<Data = null>(message?: string, data?: Data): BoomError<Data>;
|
||||
|
||||
/**
|
||||
* Returns a 500 Internal Server Error error
|
||||
* Only 500 errors will hide your message from the end user. Your message is recorded in the server log.
|
||||
* @param message optional message.
|
||||
* @param data optional additional error data.
|
||||
* @see {@link https://github.com/hapijs/boom#boombadimplementationmessage-data---alias-internal}
|
||||
*/
|
||||
export function internal<Data = null>(message?: string, data?: Data): BoomError<Data>;
|
||||
|
||||
/**
|
||||
* Returns a 501 Not Implemented error with your error message to the user
|
||||
* @param message optional message.
|
||||
* @param data optional additional error data.
|
||||
* @see {@link https://github.com/hapijs/boom#boomnotimplementedmessage-data}
|
||||
*/
|
||||
export function notImplemented<Data = null>(message?: string, data?: Data): BoomError<Data>;
|
||||
|
||||
/**
|
||||
* Returns a 502 Bad Gateway error with your error message to the user
|
||||
* @param message optional message.
|
||||
* @param data optional additional error data.
|
||||
* @see {@link https://github.com/hapijs/boom#boombadgatewaymessage-data}
|
||||
*/
|
||||
export function badGateway<Data = null>(message?: string, data?: Data): BoomError<Data>;
|
||||
|
||||
/**
|
||||
* Returns a 503 Service Unavailable error with your error message to the user
|
||||
* @param message optional message.
|
||||
* @param data optional additional error data.
|
||||
* @see {@link https://github.com/hapijs/boom#boomserverunavailablemessage-data}
|
||||
*/
|
||||
export function serverUnavailable<Data = null>(message?: string, data?: Data): BoomError<Data>;
|
||||
|
||||
/**
|
||||
* Returns a 504 Gateway Time-out error with your error message to the user
|
||||
* @param message optional message.
|
||||
* @param data optional additional error data.
|
||||
* @see {@link https://github.com/hapijs/boom#boomgatewaytimeoutmessage-data}
|
||||
*/
|
||||
export function gatewayTimeout<Data = null>(message?: string, data?: Data): BoomError<Data>;
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../../",
|
||||
"typeRoots": [
|
||||
"../../"
|
||||
],
|
||||
"types": [],
|
||||
"paths": {
|
||||
"boom": [
|
||||
"boom/v4"
|
||||
]
|
||||
},
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"boom-tests.ts"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
{
|
||||
"extends": "dtslint/dt.json",
|
||||
"rules": {
|
||||
"adjacent-overload-signatures": false,
|
||||
"array-type": false,
|
||||
"arrow-return-shorthand": false,
|
||||
"ban-types": false,
|
||||
"callable-types": false,
|
||||
"comment-format": false,
|
||||
"dt-header": false,
|
||||
"eofline": false,
|
||||
"export-just-namespace": false,
|
||||
"import-spacing": false,
|
||||
"interface-name": false,
|
||||
"interface-over-type-literal": false,
|
||||
"jsdoc-format": false,
|
||||
"max-line-length": false,
|
||||
"member-access": false,
|
||||
"new-parens": false,
|
||||
"no-any-union": false,
|
||||
"no-boolean-literal-compare": false,
|
||||
"no-conditional-assignment": false,
|
||||
"no-consecutive-blank-lines": false,
|
||||
"no-construct": false,
|
||||
"no-declare-current-package": false,
|
||||
"no-duplicate-imports": false,
|
||||
"no-duplicate-variable": false,
|
||||
"no-empty-interface": false,
|
||||
"no-for-in-array": false,
|
||||
"no-inferrable-types": false,
|
||||
"no-internal-module": false,
|
||||
"no-irregular-whitespace": false,
|
||||
"no-mergeable-namespace": false,
|
||||
"no-misused-new": false,
|
||||
"no-namespace": false,
|
||||
"no-object-literal-type-assertion": false,
|
||||
"no-padding": false,
|
||||
"no-redundant-jsdoc": false,
|
||||
"no-redundant-jsdoc-2": false,
|
||||
"no-redundant-undefined": false,
|
||||
"no-reference-import": false,
|
||||
"no-relative-import-in-test": false,
|
||||
"no-self-import": false,
|
||||
"no-single-declare-module": false,
|
||||
"no-string-throw": false,
|
||||
"no-unnecessary-callback-wrapper": false,
|
||||
"no-unnecessary-class": false,
|
||||
"no-unnecessary-generics": false,
|
||||
"no-unnecessary-qualifier": false,
|
||||
"no-unnecessary-type-assertion": false,
|
||||
"no-useless-files": false,
|
||||
"no-var-keyword": false,
|
||||
"no-var-requires": false,
|
||||
"no-void-expression": false,
|
||||
"no-trailing-whitespace": false,
|
||||
"object-literal-key-quotes": false,
|
||||
"object-literal-shorthand": false,
|
||||
"one-line": false,
|
||||
"one-variable-per-declaration": false,
|
||||
"only-arrow-functions": false,
|
||||
"prefer-conditional-expression": false,
|
||||
"prefer-const": false,
|
||||
"prefer-declare-function": false,
|
||||
"prefer-for-of": false,
|
||||
"prefer-method-signature": false,
|
||||
"prefer-template": false,
|
||||
"radix": false,
|
||||
"semicolon": false,
|
||||
"space-before-function-paren": false,
|
||||
"space-within-parens": false,
|
||||
"strict-export-declare-modifiers": false,
|
||||
"trim-file": false,
|
||||
"triple-equals": false,
|
||||
"typedef-whitespace": false,
|
||||
"unified-signatures": false,
|
||||
"void-return": false,
|
||||
"whitespace": false
|
||||
}
|
||||
}
|
||||
@@ -13,6 +13,9 @@
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"paths": {
|
||||
"boom": ["boom/v4"]
|
||||
},
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
@@ -20,4 +23,4 @@
|
||||
"index.d.ts",
|
||||
"catbox-tests.ts"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,9 @@
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"paths": {
|
||||
"boom": ["boom/v4"]
|
||||
},
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
@@ -20,4 +23,4 @@
|
||||
"index.d.ts",
|
||||
"h2o2-tests.ts"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,9 @@
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"paths": {
|
||||
"boom": ["boom/v4"]
|
||||
},
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
@@ -20,4 +23,4 @@
|
||||
"index.d.ts",
|
||||
"hapi-auth-basic-tests.ts"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,9 @@
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"paths": {
|
||||
"boom": ["boom/v4"]
|
||||
},
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
@@ -20,4 +23,4 @@
|
||||
"index.d.ts",
|
||||
"hapi-auth-jwt2-tests.ts"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,9 @@
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"paths": {
|
||||
"boom": ["boom/v4"]
|
||||
},
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
@@ -22,4 +25,4 @@
|
||||
"index.d.ts",
|
||||
"hapi-decorators-tests.ts"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,9 @@
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"paths": {
|
||||
"boom": ["boom/v4"]
|
||||
},
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
@@ -94,4 +97,4 @@
|
||||
"test/server/table.ts",
|
||||
"test/server/version.ts"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,9 @@
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"paths": {
|
||||
"boom": ["boom/v4"]
|
||||
},
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
@@ -20,4 +23,4 @@
|
||||
"index.d.ts",
|
||||
"inert-tests.ts"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,9 @@
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"paths": {
|
||||
"boom": ["boom/v4"]
|
||||
},
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
@@ -33,4 +36,4 @@
|
||||
"test/subscriptions-client.ts",
|
||||
"test/subscriptions-server.ts"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,9 @@
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"paths": {
|
||||
"boom": ["boom/v4"]
|
||||
},
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
@@ -20,4 +23,4 @@
|
||||
"index.d.ts",
|
||||
"optics-agent-tests.ts"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,9 @@
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"paths": {
|
||||
"boom": ["boom/v4"]
|
||||
},
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
@@ -20,4 +23,4 @@
|
||||
"index.d.ts",
|
||||
"swagger-express-mw-tests.ts"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,9 @@
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"paths": {
|
||||
"boom": ["boom/v4"]
|
||||
},
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
@@ -20,4 +23,4 @@
|
||||
"index.d.ts",
|
||||
"swagger-hapi-tests.ts"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,9 @@
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"paths": {
|
||||
"boom": ["boom/v4"]
|
||||
},
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
@@ -20,4 +23,4 @@
|
||||
"index.d.ts",
|
||||
"swagger-node-runner-tests.ts"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,9 @@
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"paths": {
|
||||
"boom": ["boom/v4"]
|
||||
},
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
@@ -20,4 +23,4 @@
|
||||
"index.d.ts",
|
||||
"swagger-restify-mw-tests.ts"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,9 @@
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"paths": {
|
||||
"boom": ["boom/v4"]
|
||||
},
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
@@ -20,4 +23,4 @@
|
||||
"index.d.ts",
|
||||
"swagger-sails-hook-tests.ts"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,9 @@
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"paths": {
|
||||
"boom": ["boom/v4"]
|
||||
},
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
@@ -20,4 +23,4 @@
|
||||
"index.d.ts",
|
||||
"vision-tests.ts"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user