UNPKG

unified-error-handling

Version:

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

126 lines 6.53 kB
import React, { ComponentType } from 'react'; import { ErrorFallbackProps } from './error-boundary'; import { ErrorLevel } from '../store/types'; /** * Options for withErrorBoundary HOC */ export interface WithErrorBoundaryOptions { /** * Fallback component to render when an error occurs */ fallback?: ComponentType<ErrorFallbackProps>; /** * Custom error handler */ onError?: (error: Error, errorInfo: React.ErrorInfo) => void; /** * Error level to report */ level?: ErrorLevel; /** * 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; } /** * HOC that wraps a component with an error boundary */ export declare function withErrorBoundary<P extends object>(WrappedComponent: ComponentType<P>, options?: WithErrorBoundaryOptions): React.ForwardRefExoticComponent<React.PropsWithoutRef<P> & React.RefAttributes<any>>; /** * Options for withErrorHandler HOC */ export interface WithErrorHandlerOptions { /** * Whether to automatically track component lifecycle */ trackLifecycle?: boolean; /** * Whether to automatically track performance */ trackPerformance?: boolean; /** * Custom context to include with all errors */ context?: Record<string, any>; /** * Tags to include with all errors */ tags?: Record<string, string>; /** * Whether to add navigation breadcrumbs automatically */ trackNavigation?: boolean; /** * Whether to add user action breadcrumbs automatically */ trackUserActions?: boolean; } /** * HOC that provides error handling capabilities to a component */ export declare function withErrorHandler<P extends object>(WrappedComponent: ComponentType<P>, options?: WithErrorHandlerOptions): React.ForwardRefExoticComponent<React.PropsWithoutRef<P> & React.RefAttributes<any>>; /** * Options for withAsyncErrorHandler HOC */ export interface WithAsyncErrorHandlerOptions { /** * Whether to show loading state during async operations */ showLoading?: boolean; /** * Whether to automatically retry failed operations */ autoRetry?: boolean; /** * Maximum number of retry attempts */ maxRetries?: number; /** * Custom context to include with async errors */ context?: Record<string, any>; /** * Custom error handler for async operations */ onAsyncError?: (error: Error, operation: string) => void; } /** * HOC that provides async error handling capabilities */ export declare function withAsyncErrorHandler<P extends object>(WrappedComponent: ComponentType<P>, options?: WithAsyncErrorHandlerOptions): React.ForwardRefExoticComponent<React.PropsWithoutRef<P> & React.RefAttributes<any>>; /** * HOC that combines error boundary and error handler functionality */ export declare function withErrorHandling<P extends object>(WrappedComponent: ComponentType<P>, boundaryOptions?: WithErrorBoundaryOptions, handlerOptions?: WithErrorHandlerOptions): React.ForwardRefExoticComponent<React.PropsWithoutRef<React.PropsWithoutRef<P> & React.RefAttributes<any>> & React.RefAttributes<any>>; /** * HOC that provides comprehensive error handling (boundary + handler + async) */ export declare function withCompleteErrorHandling<P extends object>(WrappedComponent: ComponentType<P>, boundaryOptions?: WithErrorBoundaryOptions, handlerOptions?: WithErrorHandlerOptions, asyncOptions?: WithAsyncErrorHandlerOptions): React.ForwardRefExoticComponent<React.PropsWithoutRef<React.PropsWithoutRef<React.PropsWithoutRef<P> & React.RefAttributes<any>> & React.RefAttributes<any>> & React.RefAttributes<any>>; /** * Utility function to create a configured error handling HOC */ export declare function createErrorHandlingHOC(defaultBoundaryOptions?: WithErrorBoundaryOptions, defaultHandlerOptions?: WithErrorHandlerOptions, defaultAsyncOptions?: WithAsyncErrorHandlerOptions): <P extends object>(WrappedComponent: ComponentType<P>, boundaryOptions?: WithErrorBoundaryOptions, handlerOptions?: WithErrorHandlerOptions, asyncOptions?: WithAsyncErrorHandlerOptions) => React.ForwardRefExoticComponent<React.PropsWithoutRef<React.PropsWithoutRef<React.PropsWithoutRef<P> & React.RefAttributes<any>> & React.RefAttributes<any>> & React.RefAttributes<any>>; /** * Pre-configured HOCs for common use cases */ export declare const withPageErrorHandling: <P extends object>(WrappedComponent: ComponentType<P>, boundaryOptions?: WithErrorBoundaryOptions, handlerOptions?: WithErrorHandlerOptions, asyncOptions?: WithAsyncErrorHandlerOptions) => React.ForwardRefExoticComponent<React.PropsWithoutRef<React.PropsWithoutRef<React.PropsWithoutRef<P> & React.RefAttributes<any>> & React.RefAttributes<any>> & React.RefAttributes<any>>; export declare const withApiErrorHandling: <P extends object>(WrappedComponent: ComponentType<P>, boundaryOptions?: WithErrorBoundaryOptions, handlerOptions?: WithErrorHandlerOptions, asyncOptions?: WithAsyncErrorHandlerOptions) => React.ForwardRefExoticComponent<React.PropsWithoutRef<React.PropsWithoutRef<React.PropsWithoutRef<P> & React.RefAttributes<any>> & React.RefAttributes<any>> & React.RefAttributes<any>>; export declare const withFormErrorHandling: <P extends object>(WrappedComponent: ComponentType<P>, boundaryOptions?: WithErrorBoundaryOptions, handlerOptions?: WithErrorHandlerOptions, asyncOptions?: WithAsyncErrorHandlerOptions) => React.ForwardRefExoticComponent<React.PropsWithoutRef<React.PropsWithoutRef<React.PropsWithoutRef<P> & React.RefAttributes<any>> & React.RefAttributes<any>> & React.RefAttributes<any>>; export declare const withCriticalErrorHandling: <P extends object>(WrappedComponent: ComponentType<P>, boundaryOptions?: WithErrorBoundaryOptions, handlerOptions?: WithErrorHandlerOptions, asyncOptions?: WithAsyncErrorHandlerOptions) => React.ForwardRefExoticComponent<React.PropsWithoutRef<React.PropsWithoutRef<React.PropsWithoutRef<P> & React.RefAttributes<any>> & React.RefAttributes<any>> & React.RefAttributes<any>>; //# sourceMappingURL=hoc.d.ts.map