import { ApiError } from '@/lib/gateways/api/base/ApiError'; import { Box } from '@/ui/Box'; import { Button } from '@/ui/Button'; import { Heading } from '@/ui/Heading'; import { Icon } from '@/ui/Icon'; import { ErrorDisplayAction, ErrorDisplayProps } from '@/ui/state-types'; import { Surface } from '@/ui/Surface'; import { Text } from '@/ui/Text'; import { AlertCircle, ArrowLeft, Home, RefreshCw } from 'lucide-react'; export function ErrorDisplay({ error, onRetry, variant = 'full-screen', actions = [], showRetry = true, showNavigation = true, hideTechnicalDetails = false, }: ErrorDisplayProps) { const getErrorInfo = () => { const isApiError = error instanceof ApiError; return { title: isApiError ? 'API Error' : 'Unexpected Error', message: error.message || 'Something went wrong', statusCode: isApiError ? error.context.statusCode : undefined, details: isApiError ? error.context.responseText : undefined, isApiError, }; }; const errorInfo = getErrorInfo(); const defaultActions: ErrorDisplayAction[] = [ ...(showRetry && onRetry ? [{ label: 'Retry', onClick: onRetry, variant: 'primary' as const, icon: RefreshCw }] : []), ...(showNavigation ? [ { label: 'Go Back', onClick: () => window.history.back(), variant: 'secondary' as const, icon: ArrowLeft }, { label: 'Home', onClick: () => window.location.href = '/', variant: 'secondary' as const, icon: Home }, ] : []), ...actions, ]; const ErrorIcon = () => ( ); switch (variant) { case 'full-screen': return ( {errorInfo.title} {errorInfo.message} {errorInfo.isApiError && errorInfo.statusCode && ( HTTP {errorInfo.statusCode} {errorInfo.details && !hideTechnicalDetails && ( - {errorInfo.details} )} )} {defaultActions.length > 0 && ( {defaultActions.map((action, index) => ( ))} )} {!hideTechnicalDetails && process.env.NODE_ENV === 'development' && error.stack && (
Technical Details {error.stack}
)}
); case 'card': return ( {errorInfo.title} {errorInfo.message} {errorInfo.isApiError && errorInfo.statusCode && ( HTTP {errorInfo.statusCode} {errorInfo.details && !hideTechnicalDetails && ` - ${errorInfo.details}`} )} {defaultActions.length > 0 && ( {defaultActions.map((action, index) => ( ))} )} ); case 'inline': return ( {errorInfo.message} {onRetry && showRetry && ( )} ); default: return null; } } export function ApiErrorDisplay({ error, onRetry, variant = 'full-screen', hideTechnicalDetails = false, }: { error: ApiError; onRetry?: () => void; variant?: 'full-screen' | 'card' | 'inline'; hideTechnicalDetails?: boolean; }) { return ( ); } export function NetworkErrorDisplay({ onRetry, variant = 'full-screen', }: { onRetry?: () => void; variant?: 'full-screen' | 'card' | 'inline'; }) { return ( ); }