UNPKG

yhttperror

Version:

Better HTTP errors for your NodeJS server.

74 lines (73 loc) 2.97 kB
import { YError } from 'yerror'; type YHTTPErrorParams = any; /** * Class representing an HTTP Error with extra debug informations * @extends Error * @extends YError */ declare class YHTTPError extends YError { httpCode: number; headers: { [name: string]: string | string[]; }; /** * Creates a new YHTTPError with an HTTP error code, an * error code and some params as debug values. * @param {number} httpCode * The HTTP error code corresponding to the actual error * @param {string} [errorCode = 'E_UNEXPECTED'] * The error code corresponding to the actual error * @param {...any} [params] * Some additional debugging values */ constructor(httpCode?: number, errorCode?: string, ...params: YHTTPErrorParams[]); /** * Wraps any error and output a YHTTPError with an HTTP * error code, an error code and some params as debug values. * @param {Error} err * The error to wrap * @param {number} httpCode * The HTTP error code corresponding to the actual error * @param {string} [errorCode = 'E_UNEXPECTED'] * The error code corresponding to the actual error * @param {...any} [params] * Some additional debugging values * @return {YHTTPError} * The wrapped error */ static wrap<E extends Error | YError | YHTTPError>(err: E, httpCode?: number | string, errorCode?: string, ...params: YHTTPErrorParams[]): YHTTPError; /** * Return YHTTPError as is or wraps any other error and output * a YHTTPError with an HTTP error code, an * error code and some params as debug values. * @param {Error} err * The error to cast * @param {number} httpCode * The HTTP error code corresponding to the actual error * @param {string} [errorCode = 'E_UNEXPECTED'] * The error code corresponding to the actual error * @param {...any} [params] * Some additional debugging values * @return {YHTTPError} * The wrapped error */ static cast<E extends Error | YError | YHTTPError>(err: E, httpCode?: number | string, errorCode?: string, ...params: YHTTPErrorParams[]): YHTTPError; /** * Same than `YHTTPError.wrap()` but preserves the HTTP code, * the error code and the debug values of the error if it is * already an instance of the YHTTPError constructor. * @param {Error} err * The error to bump * @param {number} httpCode * The HTTP error code corresponding to the actual error * @param {string} [errorCode = 'E_UNEXPECTED'] * The error code corresponding to the actual error * @param {...any} [params] * Some additional debugging values * @return {YHTTPError} * The wrapped error */ static bump<E extends Error | YError | YHTTPError>(err: E, httpCode?: number | string, errorCode?: string, ...params: YHTTPErrorParams[]): YHTTPError; toString(): string; } export { YHTTPError };