error-advisor
Version:
NPM module that aim to facilitate the error handling by providing http errors classes and also let you customize business errors as well with handy and clean way.
14 lines (13 loc) • 1.99 kB
TypeScript
import { ExcepectationFailed, Forbidden, Gone, Conflict, BadRequest, Unauthorized, IAmATeapot, LengthRequired, MethodNotAllowed, NotAcceptable, NotFound, PayloadTooLarge, PaymentRequied, PreconditionFailed, PreconditionRequired, ProxyAuthenticationRequired, RangeNotSatisfiable, RequestHeaderFieldsTooLarge, RequestTimeout, TooEarly, TooManyRequests, UnavailableForLegalReasons, UnprocessableEntity, UnsupportedMediaType, UpgradeRequired, URITooLong } from "../error/client_error/Client_Errors";
import { BadGateway, GatewayTimeout, HttpVersionNotSupported, InsufficientStorage, InternalServerError, LoopDetected, NetworkAuthenticationRequired, NotExtended, NotImplemented, ServiceUnavailable, VariantAlsoNegotiates } from "../error/server_error/Server_Errors";
export default class Utils {
static errorBuilder(msg: string, type: any, statusCode: any, timestamp: string): any;
static isClientError(statusCode: number): boolean;
static isServerError(statusCode: number): boolean;
/**
* Utility function that create error object based on the status code given,
* @param status
* @param message Optional parameter if it's exist it's value will be used either the default value will be picked.
*/
static errorFactory(status: number, message?: string): BadRequest | Conflict | ExcepectationFailed | Forbidden | Gone | IAmATeapot | LengthRequired | MethodNotAllowed | NotAcceptable | NotFound | PayloadTooLarge | PaymentRequied | PreconditionFailed | PreconditionRequired | ProxyAuthenticationRequired | RangeNotSatisfiable | RequestHeaderFieldsTooLarge | RequestTimeout | TooEarly | TooManyRequests | Unauthorized | UnavailableForLegalReasons | UnprocessableEntity | UnsupportedMediaType | UpgradeRequired | URITooLong | BadGateway | GatewayTimeout | HttpVersionNotSupported | InsufficientStorage | InternalServerError | LoopDetected | NetworkAuthenticationRequired | NotExtended | NotImplemented | ServiceUnavailable | VariantAlsoNegotiates;
}