UNPKG

express-hale

Version:

🚀 Interactive Express.js scaffold CLI with comprehensive error handling, TypeScript/JavaScript, database integrations, Git Flow, and development tools

145 lines • 4.92 kB
import { Request, Response, NextFunction } from 'express'; export interface ErrorContext { operation: string; projectName?: string; projectPath?: string; phase: 'initialization' | 'generation' | 'cleanup'; timestamp: Date; requestId?: string; userId?: string; ip?: string; userAgent?: string; } export interface RetryStrategy { maxAttempts: number; initialDelay: number; backoffMultiplier: number; maxDelay: number; } export interface CircuitBreakerConfig { failureThreshold: number; resetTimeout: number; monitoringPeriod: number; } export declare enum HttpStatusCode { OK = 200, CREATED = 201, ACCEPTED = 202, NO_CONTENT = 204, MOVED_PERMANENTLY = 301, FOUND = 302, NOT_MODIFIED = 304, BAD_REQUEST = 400, UNAUTHORIZED = 401, FORBIDDEN = 403, NOT_FOUND = 404, METHOD_NOT_ALLOWED = 405, CONFLICT = 409, UNPROCESSABLE_ENTITY = 422, TOO_MANY_REQUESTS = 429, INTERNAL_SERVER_ERROR = 500, BAD_GATEWAY = 502, SERVICE_UNAVAILABLE = 503, GATEWAY_TIMEOUT = 504 } export declare enum ErrorCategory { VALIDATION = "VALIDATION", AUTHENTICATION = "AUTHENTICATION", AUTHORIZATION = "AUTHORIZATION", NOT_FOUND = "NOT_FOUND", BUSINESS_LOGIC = "BUSINESS_LOGIC", EXTERNAL_SERVICE = "EXTERNAL_SERVICE", DATABASE = "DATABASE", NETWORK = "NETWORK", SYSTEM = "SYSTEM", UNKNOWN = "UNKNOWN" } export interface ApiResponse<T = any> { success: boolean; data?: T; error?: { code: string; message: string; details?: any; category: ErrorCategory; timestamp: string; requestId?: string; }; meta?: { timestamp: string; version: string; requestId?: string; }; } export declare class CLIError extends Error { readonly code: string; readonly context: ErrorContext; readonly originalError?: Error; constructor(message: string, code: string, context: ErrorContext, originalError?: Error); } export declare class HttpError extends Error { readonly statusCode: HttpStatusCode; readonly code: string; readonly category: ErrorCategory; readonly isOperational: boolean; readonly context?: Record<string, any>; readonly originalError?: Error; constructor(message: string, statusCode?: HttpStatusCode, code?: string, category?: ErrorCategory, isOperational?: boolean, context?: Record<string, any>, originalError?: Error); } export declare class ValidationError extends HttpError { constructor(message: string, details?: any); } export declare class AuthenticationError extends HttpError { constructor(message?: string); } export declare class AuthorizationError extends HttpError { constructor(message?: string); } export declare class NotFoundError extends HttpError { constructor(resource?: string); } export declare class ConflictError extends HttpError { constructor(message: string); } export declare class RateLimitError extends HttpError { constructor(message?: string); } export declare class ExternalServiceError extends HttpError { constructor(service: string, message?: string); } export declare class DatabaseError extends HttpError { constructor(message: string, operation?: string); } export declare class ResponseFormatter { static success<T>(data: T, meta?: any): ApiResponse<T>; static error(error: HttpError | Error, requestId?: string): ApiResponse; } export declare class ErrorHandler { private static instance; private logFile?; private retryStrategies; private constructor(); static getInstance(): ErrorHandler; private setupDefaultRetryStrategies; setLogFile(projectPath?: string): void; handleError(error: Error | CLIError, exitCode?: number): Promise<never>; private logStructuredError; private logGenericError; private writeLog; private displayUserFriendlyError; private displayGenericError; private displaySolutions; private displaySupportInfo; cleanup(projectPath?: string): Promise<void>; createErrorMiddleware(): (error: Error, req: Request, res: Response) => void; createNotFoundMiddleware(): (req: Request, res: Response, next: NextFunction) => void; createRequestIdMiddleware(): (req: Request, res: Response, next: NextFunction) => void; asyncHandler(fn: (req: Request, res: Response, next: NextFunction) => Promise<any>): (req: Request, res: Response, next: NextFunction) => void; retry<T>(operation: () => Promise<T>, errorCode: string, context?: Record<string, any>): Promise<T>; private logHttpError; private generateRequestId; private delay; createCircuitBreaker<T extends (...args: any[]) => Promise<any>>(operation: T, config: CircuitBreakerConfig): T; } export declare function setupGlobalErrorHandlers(): void; //# sourceMappingURL=error-handler.d.ts.map