'use client'; import { ApiError } from '@/lib/api/base/ApiError'; import { AlertTriangle, Wifi, RefreshCw, ArrowLeft } from 'lucide-react'; import { useRouter } from 'next/navigation'; import { useState } from 'react'; interface ErrorDisplayProps { error: ApiError; onRetry?: () => void; } /** * User-friendly error display for production environments */ export function ErrorDisplay({ error, onRetry }: ErrorDisplayProps) { const router = useRouter(); const [isRetrying, setIsRetrying] = useState(false); const userMessage = error.getUserMessage(); const isConnectivity = error.isConnectivityIssue(); const handleRetry = async () => { if (onRetry) { setIsRetrying(true); try { onRetry(); } finally { setIsRetrying(false); } } }; const handleGoBack = () => { router.back(); }; const handleGoHome = () => { router.push('/'); }; return (
{/* Header */}
{isConnectivity ? ( ) : ( )}

{isConnectivity ? 'Connection Issue' : 'Something Went Wrong'}

Error {error.context.statusCode || 'N/A'}

{/* Body */}

{userMessage}

{/* Details for debugging (collapsed by default) */}
Technical Details
Type: {error.type}
Endpoint: {error.context.endpoint || 'N/A'}
{error.context.statusCode &&
Status: {error.context.statusCode}
} {error.context.retryCount !== undefined && (
Retries: {error.context.retryCount}
)}
{/* Action Buttons */}
{error.isRetryable() && ( )}
{/* Footer */}
If this persists, please contact support at{' '} support@gridpilot.com
); } /** * Full-screen error display with more context */ export function FullScreenError({ error, onRetry }: ErrorDisplayProps) { return (
); }