UNPKG

@agentman/chat-widget

Version:

Agentman Chat Widget for easy integration with web applications

63 lines (62 loc) 2.24 kB
import type { Message } from '../types/types'; import { MessageService } from '../services/MessageService'; import type { EventBus } from '../utils/EventBus'; /** * ErrorHandler - Centralized error handling and user feedback * * This class provides: * - Consistent error messaging and formatting * - Different error types (API, validation, network, etc.) * - User-friendly error messages * - Integration with EventBus for error events * - Recovery suggestions where applicable */ export declare class ErrorHandler { private logger; private messageService; private eventBus; constructor(messageService: MessageService, eventBus: EventBus, debug?: boolean); /** * Handle API errors with appropriate user feedback */ handleApiError(error: Error, endpoint?: string, context?: string): Message; /** * Handle validation errors */ handleValidationError(field: string, value: any, constraint: string): Message; /** * Handle file upload errors */ handleFileError(fileName: string, error: 'size' | 'type' | 'upload' | 'network', details?: { maxSize?: number; allowedTypes?: string[]; }): Message; /** * Handle general application errors */ handleApplicationError(operation: string, error: Error, recoverable?: boolean): Message; /** * Handle configuration errors */ handleConfigurationError(configKey: string, expectedType: string, actualValue: any): void; /** * Handle persistence/storage errors */ handleStorageError(operation: 'save' | 'load' | 'delete', error: Error, storageKey?: string): Message; /** * Create a user-friendly error message for display */ createUserErrorMessage(content: string): Message; /** * Log error for debugging without user notification */ logError(context: string, error: Error, additionalData?: Record<string, any>): void; /** * Handle unknown/unexpected errors with fallback behavior */ handleUnknownError(error: unknown, context?: string, showToUser?: boolean): Message | null; /** * Get recovery suggestions for different error types */ getRecoverySuggestions(errorType: string): string[]; }