/** * Enhanced error handling with circuit breaker and observability */ import { Logger } from 'winston'; import { ErrorContext } from './ErrorHandling.js'; import { RetryStrategy, RetryConfig } from './RetryStrategy.js'; import { CircuitBreaker, CircuitBreakerConfig, CircuitBreakerFactory } from './CircuitBreaker.js'; /** * Error handler interface */ export interface IErrorHandler { /** * Handle an error * @returns true if error was handled, false to propagate */ handle(error: any, context?: ErrorContext): Promise | boolean; /** * Transform an error */ transform?(error: any, context?: ErrorContext): any; /** * Check if handler can handle this error */ canHandle?(error: any): boolean; } /** * Error handler chain configuration */ export interface ErrorHandlerChainConfig { handlers: IErrorHandler[]; logger?: Logger; stopOnFirstHandled?: boolean; } /** * Composite error handler that chains multiple handlers */ export declare class ErrorHandlerChain implements IErrorHandler { private readonly handlers; private readonly logger?; private readonly stopOnFirstHandled; constructor(config: ErrorHandlerChainConfig); handle(error: any, context?: ErrorContext): Promise; transform(error: any, context?: ErrorContext): any; canHandle(error: any): boolean; /** * Add a handler to the chain */ addHandler(handler: IErrorHandler): void; /** * Remove a handler from the chain */ removeHandler(handler: IErrorHandler): void; } /** * Logging error handler */ export declare class LoggingErrorHandler implements IErrorHandler { private readonly logger; private readonly logLevel; constructor(logger: Logger, logLevel?: 'error' | 'warn' | 'info'); handle(error: any, context?: ErrorContext): boolean; } /** * Retry error handler with configurable strategy */ export declare class RetryErrorHandler implements IErrorHandler { private readonly retryStrategy; constructor(retryConfig?: Partial, logger?: Logger); canHandle(error: any): boolean; handle(_error: any, _context?: ErrorContext): Promise; /** * Get the retry strategy for use in operations */ getRetryStrategy(): RetryStrategy; } /** * Circuit breaker error handler */ export declare class CircuitBreakerErrorHandler implements IErrorHandler { private readonly circuitBreakerFactory; private readonly defaultConfig; constructor(defaultConfig?: Partial>, logger?: Logger); handle(_error: any, context?: ErrorContext): boolean; /** * Get or create a circuit breaker for an operation */ getCircuitBreaker(operationName: string): CircuitBreaker; /** * Get circuit breaker factory */ getFactory(): CircuitBreakerFactory; /** * Cleanup resources */ dispose(): void; } /** * Transformation error handler that enriches errors with context */ export declare class ContextEnrichmentHandler implements IErrorHandler { handle(_error: any, _context?: ErrorContext): boolean; transform(error: any, context?: ErrorContext): any; } /** * Rate limit error handler with backoff */ export declare class RateLimitHandler implements IErrorHandler { private readonly logger?; private readonly rateLimits; constructor(logger?: Logger | undefined); canHandle(error: any): boolean; handle(error: any, context?: ErrorContext): Promise; /** * Check if operation is currently rate limited */ isRateLimited(operation: string): boolean; /** * Get remaining wait time for rate limited operation */ getRemainingWaitTime(operation: string): number; } /** * Default error handler factory */ export declare class ErrorHandlerFactory { static createDefault(logger?: Logger): ErrorHandlerChain; static createWithRetry(retryConfig?: Partial, logger?: Logger): ErrorHandlerChain; static createWithCircuitBreaker(circuitConfig?: Partial>, logger?: Logger): ErrorHandlerChain; static createComplete(retryConfig?: Partial, circuitConfig?: Partial>, logger?: Logger): { chain: ErrorHandlerChain; retryHandler: RetryErrorHandler; circuitHandler: CircuitBreakerErrorHandler; }; } /** * Error recovery strategies */ export interface IErrorRecovery { /** * Attempt to recover from an error * @returns Recovery result or throws if recovery fails */ recover(error: any, context?: ErrorContext): Promise | T; } /** * Fallback recovery strategy */ export declare class FallbackRecovery implements IErrorRecovery { private readonly fallbackValue; private readonly condition?; constructor(fallbackValue: T | (() => T | Promise), condition?: ((error: any) => boolean) | undefined); recover(error: any, _context?: ErrorContext): Promise; } /** * Cache-based recovery strategy */ export declare class CacheRecovery implements IErrorRecovery { private readonly cacheKey; private readonly ttlMs; private cache; constructor(cacheKey: (context?: ErrorContext) => string, ttlMs?: number); recover(error: any, context?: ErrorContext): Promise; /** * Store value in cache */ store(value: T, context?: ErrorContext): void; /** * Clear cache */ clear(): void; } //# sourceMappingURL=ErrorHandler.d.ts.map