UNPKG

@ai-growth/nextjs

Version:

Seamlessly integrate Sanity CMS with Next.js applications for automated blog routing and rendering

114 lines 4.3 kB
import React, { Component, ErrorInfo, ReactNode } from 'react'; export interface ErrorDetails { error: Error; errorInfo: ErrorInfo; timestamp: Date; userAgent?: string; url?: string; userId?: string; sessionId?: string; additionalContext?: Record<string, any>; } export interface ErrorBoundaryProps { /** Child components to protect */ children: ReactNode; /** Custom fallback UI component or render function */ fallback?: ReactNode | ((errorDetails: ErrorDetails) => ReactNode); /** Error handler callback */ onError?: (errorDetails: ErrorDetails) => void; /** Whether to isolate errors to this boundary only */ isolate?: boolean; /** Custom error classification */ errorLevel?: 'warning' | 'error' | 'critical'; /** Additional context to include in error reports */ context?: Record<string, any>; /** Whether to enable retry functionality */ enableRetry?: boolean; /** Maximum number of retry attempts */ maxRetries?: number; /** Custom CSS class for styling */ className?: string; /** Whether to show error details in development */ showErrorDetails?: boolean; } export interface ErrorBoundaryState { hasError: boolean; error: Error | null; errorInfo: ErrorInfo | null; retryCount: number; errorId: string; } /** * Base ErrorBoundary component that catches JavaScript errors anywhere in the child component tree * and displays a fallback UI instead of crashing the entire application. * * @example * ```tsx * <ErrorBoundary * fallback={<ErrorFallback />} * onError={(errorDetails) => logError(errorDetails)} * enableRetry={true} * > * <MyComponent /> * </ErrorBoundary> * ``` */ export declare class ErrorBoundary extends Component<ErrorBoundaryProps, ErrorBoundaryState> { private retryTimeoutId; constructor(props: ErrorBoundaryProps); static getDerivedStateFromError(error: Error): Partial<ErrorBoundaryState>; componentDidCatch(error: Error, errorInfo: ErrorInfo): void; componentWillUnmount(): void; handleRetry: () => void; handleReset: () => void; render(): string | number | bigint | boolean | Iterable<React.ReactNode> | Promise<React.AwaitedReactNode> | import("react/jsx-runtime").JSX.Element | null | undefined; } /** * Specialized error boundary for CMS content rendering */ export interface CmsErrorBoundaryProps extends Omit<ErrorBoundaryProps, 'fallback'> { /** Custom fallback content for CMS errors */ fallback?: ReactNode | ((errorDetails: ErrorDetails) => ReactNode); /** Content slug for error context */ contentSlug?: string; /** Content type for error context */ contentType?: string; } export declare const CmsErrorBoundary: React.FC<CmsErrorBoundaryProps>; /** * Specialized error boundary for API operations */ export interface ApiErrorBoundaryProps extends Omit<ErrorBoundaryProps, 'fallback'> { /** Custom fallback content for API errors */ fallback?: ReactNode | ((errorDetails: ErrorDetails) => ReactNode); /** API endpoint for error context */ endpoint?: string; /** Operation type for error context */ operation?: string; } export declare const ApiErrorBoundary: React.FC<ApiErrorBoundaryProps>; /** * Specialized error boundary for template rendering */ export interface TemplateErrorBoundaryProps extends Omit<ErrorBoundaryProps, 'fallback'> { /** Custom fallback content for template errors */ fallback?: ReactNode | ((errorDetails: ErrorDetails) => ReactNode); /** Template name for error context */ templateName?: string; /** Content type being rendered */ contentType?: string; } export declare const TemplateErrorBoundary: React.FC<TemplateErrorBoundaryProps>; /** * Higher-order component that wraps a component with an error boundary */ export declare function withErrorBoundary<P extends object>(Component: React.ComponentType<P>, errorBoundaryProps?: Omit<ErrorBoundaryProps, 'children'>): { (props: P): import("react/jsx-runtime").JSX.Element; displayName: string; }; /** * Hook to throw an error for testing error boundaries */ export declare function useErrorThrower(): (error: string | Error) => never; export default ErrorBoundary; //# sourceMappingURL=ErrorBoundary.d.ts.map