import { PlatformError } from './base.errors.js'; import type { IErrorContext } from './base.errors.js'; /** * Error handler configuration */ export interface IErrorHandlerConfig { /** Whether to log errors automatically */ logErrors: boolean; /** Whether to include stack traces in prod environment */ includeStacksInProd: boolean; /** Default retry options */ retry: { /** Maximum retry attempts */ maxAttempts: number; /** Base delay between retries in ms */ baseDelay: number; /** Maximum delay between retries in ms */ maxDelay: number; /** Backoff factor for exponential backoff */ backoffFactor: number; }; } /** * Error handler utility * Provides methods for consistent error handling across the platform */ export declare class ErrorHandler { /** * Current configuration */ static config: IErrorHandlerConfig; /** * Update error handler configuration * * @param newConfig New configuration (partial) */ static configure(newConfig: Partial): void; /** * Convert any error to a PlatformError * * @param error Error to convert * @param defaultCode Default error code if not a PlatformError * @param context Additional context * @returns PlatformError instance */ static toPlatformError(error: any, defaultCode: string, context?: IErrorContext): PlatformError; /** * Format an error for API responses * Sanitizes errors for safe external exposure * * @param error Error to format * @param includeDetails Whether to include detailed information * @returns Formatted error object */ static formatErrorForResponse(error: any, includeDetails?: boolean): Record; /** * Handle an error with consistent logging and formatting * * @param error Error to handle * @param defaultCode Default error code if not a PlatformError * @param context Additional context * @returns Formatted error for response */ static handleError(error: any, defaultCode: string, context?: IErrorContext): Record; /** * Execute a function with error handling * * @param fn Function to execute * @param defaultCode Default error code if the function throws * @param context Additional context * @returns Function result or error */ static execute(fn: () => Promise, defaultCode: string, context?: IErrorContext): Promise; /** * Execute a function with retries and exponential backoff * * @param fn Function to execute * @param defaultCode Default error code if the function throws * @param options Retry options * @param context Additional context * @returns Function result or error after max retries */ static executeWithRetry(fn: () => Promise, defaultCode: string, options?: { maxAttempts?: number; baseDelay?: number; maxDelay?: number; backoffFactor?: number; retryableErrorCodes?: string[]; retryableErrorPatterns?: RegExp[]; onRetry?: (error: PlatformError, attempt: number, delay: number) => void; }, context?: IErrorContext): Promise; } /** * Create a middleware for handling errors in HTTP requests * * @returns Middleware function */ export declare function createErrorHandlerMiddleware(): (error: any, req: any, res: any, next: any) => void;