/** * # Error Context * * React Context for centralized error state management across the application. * Provides error tracking, toast notifications, and error recovery actions. * * ## Business Perspective * Centralizes error handling state management, enabling consistent error tracking * and user notifications across the entire application. Critical for operational * excellence and user experience. 🛡️ * * ## Technical Perspective * React Context that manages error state, toast notifications, and provides * actions for error handling. Integrates with centralized error service for * logging and user-friendly message generation. * * @packageDocumentation */ import React, { ReactNode } from 'react'; import { ToastPosition } from '../components/common/ErrorToast'; /** * Error entry for tracking errors */ export interface ErrorEntry { /** Unique error ID */ id: string; /** Error object */ error: Error; /** User-friendly error message */ message: string; /** Error timestamp */ timestamp: Date; /** Whether the error is recoverable */ recoverable: boolean; /** Error context */ context?: Record; } /** * Toast notification configuration */ export interface ToastConfig { /** Toast message */ message: string; /** Toast title (optional) */ title?: string; /** Auto-hide duration in milliseconds */ autoHideDuration?: number; /** Toast position */ position?: ToastPosition; /** Retry callback (optional) - aligns with ErrorToast component API */ retry?: () => void; } /** * Error context value */ export interface ErrorContextValue { /** List of tracked errors */ errors: ErrorEntry[]; /** Add an error to tracking */ addError: (error: Error, context?: Record) => void; /** Clear a specific error */ clearError: (id: string) => void; /** Clear all errors */ clearAllErrors: () => void; /** Show a toast notification */ showToast: (config: ToastConfig) => void; /** Hide the current toast */ hideToast: () => void; /** Get the most recent error */ getLatestError: () => ErrorEntry | undefined; } /** * Props for ErrorProvider */ export interface ErrorProviderProps { /** Child components */ children: ReactNode; /** Maximum number of errors to track */ maxErrors?: number; /** Default toast position */ defaultToastPosition?: ToastPosition; /** Default toast auto-hide duration */ defaultAutoHideDuration?: number; } /** * Error Provider Component * * Provides error context to child components, managing error state and * toast notifications. * * @example * ```tsx * // Wrap application with ErrorProvider * * * * * // Use in components * const { addError, showToast } = useError(); * * try { * await fetchData(); * } catch (error) { * addError(error, { component: 'DataFetcher' }); * showToast({ * message: 'Failed to load data', * retry: () => fetchData() * }); * } * ``` */ export declare const ErrorProvider: React.FC; /** * Custom hook to use error context * * @throws Error if used outside ErrorProvider * @returns Error context value * * @example * ```tsx * const { addError, showToast, clearError } = useError(); * * // Track and display error * try { * await saveData(); * } catch (error) { * addError(error, { operation: 'save' }); * showToast({ * message: 'Failed to save data', * retry: () => saveData() * }); * } * ``` */ export declare const useError: () => ErrorContextValue; export default ErrorProvider; //# sourceMappingURL=ErrorContext.d.ts.map