'use client'; import * as Sentry from '@sentry/nextjs'; import { useTranslations } from 'next-intl'; import { useEffect, useState } from 'react'; export default function GlobalError({ error, reset, }: { error: Error & { digest?: string }; reset: () => void; }) { const [retryCount, setRetryCount] = useState(0); const [autoRetrying, setAutoRetrying] = useState(false); const t = useTranslations(); useEffect(() => { Sentry.captureException(error); if (process.env.NODE_ENV !== 'production') { console.error('Unhandled error:', error); } }, [error]); // Auto-retry once after 3 seconds useEffect(() => { if (retryCount > 0) return; setAutoRetrying(true); const timer = setTimeout(() => { setAutoRetrying(false); setRetryCount((c) => c + 1); reset(); }, 3000); return () => clearTimeout(timer); }, [error, reset, retryCount]); const handleRetry = () => { setRetryCount((c) => c + 1); reset(); }; return (

{t('error.title')}

{autoRetrying ? t('error.autoRetrying') : t('error.description')}

{error.digest && (

{t('common.errorCode', { code: error.digest })}

)} {retryCount > 0 && (

{t('common.retriedCount', { count: retryCount })}

)}
{t('common.goHome')}
); }