'use client'; import posthog from 'posthog-js'; import { useEffect, useState } from 'react'; import { useEnv } from '@/context/EnvContext'; import { useTranslation } from '@/hooks/useTranslation'; import { parseWebViewInfo } from '@/utils/ua'; import { handleGlobalError } from '@/utils/error'; interface ErrorPageProps { error: Error & { digest?: string }; reset: () => void; } export default function Error({ error, reset }: ErrorPageProps) { const _ = useTranslation(); const { appService } = useEnv(); const [browserInfo, setBrowserInfo] = useState(''); useEffect(() => { setBrowserInfo(parseWebViewInfo(appService)); }, [appService]); useEffect(() => { posthog.captureException(error); handleGlobalError(error); }, [appService, error]); const handleGoHome = () => { window.location.href = '/library'; }; const handleGoBack = () => { if (window.history.length > 1) { window.history.back(); } else { handleGoHome(); } }; return (
{_( "Something went wrong. Don't worry, our team has been notified and we're working on a fix.", )}
{error.message}
{browserInfo && (Browser: {browserInfo}
)} {error.stack && ({error.stack.split('\n').slice(0, 3).join('\n')}
)} {error.digest && (Error ID: {error.digest}
)}{_('Need help?')}{' '} {_('Contact Support')}