UNPKG

handle-http-errors

Version:

Type-safe HTTP error handling package providing error classes, standardized responses, error handler, and built-in Express middleware support.

39 lines (38 loc) 1.73 kB
import { ReasonPhrases, StatusCodes } from "http-status-codes"; import { ErrorDetails } from "./types"; export declare class HttpError extends Error { status: number; code: string; details?: ErrorDetails | undefined; constructor(status: number, code: string, message: string, details?: ErrorDetails | undefined); static isHttpError(error: unknown): error is HttpError; } export declare class ValidationError extends HttpError { constructor(message?: string, details?: ErrorDetails); static isValidationError(error: unknown): error is ValidationError; } export declare class BadRequestError extends HttpError { constructor(message?: string, details?: ErrorDetails); static isBadRequestError(error: unknown): error is BadRequestError; } export declare class UnauthorizedError extends HttpError { constructor(message?: string, details?: ErrorDetails); static isUnauthorizedError(error: unknown): error is UnauthorizedError; } export declare class ForbiddenError extends HttpError { constructor(message?: string, details?: ErrorDetails); static isForbiddenError(error: unknown): error is ForbiddenError; } export declare class NotFoundError extends HttpError { constructor(message?: string, details?: ErrorDetails); static isNotFoundError(error: unknown): error is NotFoundError; } export declare class InternalServerError extends HttpError { constructor(message?: string, details?: ErrorDetails); static isInternalServerError(error: unknown): error is InternalServerError; } export declare const DEFAULT_ERROR: { readonly status: StatusCodes.INTERNAL_SERVER_ERROR; readonly code: "INTERNAL_ERROR"; readonly message: ReasonPhrases.INTERNAL_SERVER_ERROR; };