UNPKG

unified-error-handling

Version:

A lightweight, zero-dependency error handling library with dynamic adapter loading for multiple error tracking services

108 lines 3.04 kB
import React, { Component, ReactNode, ErrorInfo } from 'react'; /** * Error boundary props */ export interface ErrorBoundaryProps { /** * Fallback component to render when an error occurs */ fallback?: React.ComponentType<ErrorFallbackProps>; /** * Custom error handler */ onError?: (error: Error, errorInfo: ErrorInfo) => void; /** * Error level to report */ level?: 'debug' | 'info' | 'warning' | 'error' | 'fatal'; /** * Additional context to include with the error */ context?: Record<string, any>; /** * Tags to include with the error */ tags?: Record<string, string>; /** * Whether to isolate errors (prevent propagation to parent boundaries) */ isolate?: boolean; /** * Whether to reset on prop changes */ resetOnPropsChange?: boolean; /** * Custom reset key - when this changes, the error boundary resets */ resetKey?: string | number; /** * Children to render */ children: ReactNode; } /** * Error boundary state */ export interface ErrorBoundaryState { hasError: boolean; error: Error | null; errorInfo: ErrorInfo | null; errorId: string | null; } /** * Error fallback props */ export interface ErrorFallbackProps { error: Error; errorInfo: ErrorInfo; errorId: string | null; resetError: () => void; retry: () => void; } /** * Error boundary component */ export declare class ErrorBoundary extends Component<ErrorBoundaryProps, ErrorBoundaryState> { private resetTimeoutId; private retryCount; private maxRetries; constructor(props: ErrorBoundaryProps); /** * Catch errors in child components */ static getDerivedStateFromError(error: Error): Partial<ErrorBoundaryState>; /** * Handle component errors */ componentDidCatch(error: Error, errorInfo: ErrorInfo): void; /** * Reset error boundary on prop changes */ componentDidUpdate(prevProps: ErrorBoundaryProps): void; /** * Cleanup on unmount */ componentWillUnmount(): void; /** * Handle error reporting */ private handleError; /** * Reset error state */ private resetError; /** * Retry with exponential backoff */ private retry; render(): string | number | bigint | boolean | Iterable<React.ReactNode> | Promise<string | number | bigint | boolean | React.ReactPortal | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | Iterable<React.ReactNode> | null | undefined> | import("react/jsx-runtime").JSX.Element | null | undefined; } /** * Default error fallback component */ export declare const DefaultErrorFallback: React.FC<ErrorFallbackProps>; /** * Hook-based error boundary wrapper */ export declare const withErrorBoundary: <P extends object>(Component: React.ComponentType<P>, errorBoundaryProps?: Omit<ErrorBoundaryProps, "children">) => React.FC<P>; //# sourceMappingURL=error-boundary.d.ts.map