/* eslint-disable i18next/no-literal-string */ import { Button } from '@librechat/client'; import { useRouteError } from 'react-router-dom'; import logger from '~/utils/logger'; interface UserAgentData { getHighEntropyValues(hints: string[]): Promise<{ platform: string; platformVersion: string }>; } type PlatformInfo = { os: string; version?: string; }; const formatStackTrace = (stack: string) => { return stack .split('\n') .map((line) => line.trim()) .filter(Boolean) .map((line, i) => ({ number: i + 1, content: line, })); }; const getPlatformInfo = async (): Promise => { if ('userAgentData' in navigator) { try { const ua = navigator.userAgentData as UserAgentData; const highEntropyValues = await ua.getHighEntropyValues(['platform', 'platformVersion']); return { os: highEntropyValues.platform, version: highEntropyValues.platformVersion, }; } catch (e) { logger.warn('Failed to get high entropy values'); logger.error(e); } } const userAgent = navigator.userAgent.toLowerCase(); if (userAgent.includes('mac')) { return { os: 'macOS' }; } if (userAgent.includes('win')) { return { os: 'Windows' }; } if (userAgent.includes('linux')) { return { os: 'Linux' }; } if (userAgent.includes('android')) { return { os: 'Android' }; } if (userAgent.includes('ios') || userAgent.includes('iphone') || userAgent.includes('ipad')) { return { os: 'iOS' }; } return { os: 'Unknown' }; }; const getBrowserInfo = async () => { const platformInfo = await getPlatformInfo(); return { userAgent: navigator.userAgent, platform: platformInfo.os, platformVersion: platformInfo.version, language: navigator.language, windowSize: `${window.innerWidth}x${window.innerHeight}`, }; }; export default function RouteErrorBoundary() { const typedError = useRouteError() as { message?: string; stack?: string; status?: number; statusText?: string; data?: unknown; }; const errorDetails = { message: typedError.message ?? 'An unexpected error occurred', stack: typedError.stack, status: typedError.status, statusText: typedError.statusText, data: typedError.data, }; const handleDownloadLogs = async () => { try { const browser = await getBrowserInfo(); const errorLog = { timestamp: new Date().toISOString(), browser, error: { ...errorDetails, stack: errorDetails.stack != null && errorDetails.stack.trim() !== '' ? formatStackTrace(errorDetails.stack) : undefined, }, }; const blob = new Blob([JSON.stringify(errorLog, null, 2)], { type: 'application/json' }); const url = URL.createObjectURL(blob); const a = document.createElement('a'); a.href = url; a.download = `error-log-${new Date().toISOString()}.json`; document.body.appendChild(a); a.click(); document.body.removeChild(a); URL.revokeObjectURL(url); } catch (e) { logger.warn('Failed to download error logs:'); logger.error(e); } }; const handleCopyStack = async () => { if (errorDetails.stack != null && errorDetails.stack !== '') { await navigator.clipboard.writeText(errorDetails.stack); } }; return (

Oops! Something Unexpected Occurred

{/* Error Message */}

Error Message:

            {errorDetails.message}
          
{/* Status Information */} {(typeof errorDetails.status === 'number' || typeof errorDetails.statusText === 'string') && (

Status:

{typeof errorDetails.status === 'number' && `${errorDetails.status} `} {typeof errorDetails.statusText === 'string' && errorDetails.statusText}

)} {/* Stack Trace - Collapsible */} {errorDetails.stack != null && errorDetails.stack.trim() !== '' && (
Stack Trace
{formatStackTrace(errorDetails.stack).map(({ number, content }) => (
{String(number).padStart(3, '0')}
                    {content}
                  
))}
)} {/* Additional Error Data */} {errorDetails.data != null && (
Additional Details {'>'}
              {JSON.stringify(errorDetails.data, null, 2)}
            
)}

Please try one of the following:

  • Refresh the page
  • Clear your browser cache
  • Check your internet connection
  • Contact the Admin if the issue persists
); }