diff --git a/frontend/next.config.mjs b/frontend/next.config.mjs index 53c683e..74249cf 100644 --- a/frontend/next.config.mjs +++ b/frontend/next.config.mjs @@ -34,6 +34,11 @@ const nextConfig = { hostname: '**', }, ], + localPatterns: [ + { + pathname: '/api/**', + }, + ], }, }; diff --git a/frontend/src/components/ErrorBoundary.tsx b/frontend/src/components/ErrorBoundary.tsx index f6090f4..0b96131 100644 --- a/frontend/src/components/ErrorBoundary.tsx +++ b/frontend/src/components/ErrorBoundary.tsx @@ -47,19 +47,13 @@ class ErrorBoundary extends Component { } } - async componentWillUnmount() { + componentWillUnmount() { if (process.env.NODE_ENV !== 'production') { logger.debug('componentWillUnmount'); - const response = await fetch('/api/logError', { - method: 'DELETE', - }); - - const data = await response.json(); - logger.debug('Error logs cleared:', data); } } - async componentDidCatch(error: Error, errorInfo: ErrorInfo) { + componentDidCatch(error: Error, errorInfo: ErrorInfo) { // Update state with error details (always needed for UI) this.setState({ errorInfo: errorInfo, @@ -68,47 +62,6 @@ class ErrorBoundary extends Component { // Only perform logging in non-production environments if (process.env.NODE_ENV !== 'production') { logger.info('Error caught in boundary:', { error, errorInfo }); - - // Function to log errors to the server - const logErrorToServer = async () => { - try { - const response = await fetch('/api/logError', { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - }, - body: JSON.stringify({ - message: error.message, - stack: errorInfo.componentStack, - }), - }); - - const data = await response.json(); - logger.debug('Error logged:', data); - } catch (err) { - logger.error( - 'Failed to log error:', - err instanceof Error ? err : { error: err }, - ); - } - }; - - // Function to fetch logged errors (optional) - const fetchLoggedErrors = async () => { - try { - const response = await fetch('/api/logError'); - const data = await response.json(); - logger.debug('Fetched logs:', data); - } catch (err) { - logger.error( - 'Failed to fetch logs:', - err instanceof Error ? err : { error: err }, - ); - } - }; - - await logErrorToServer(); - await fetchLoggedErrors(); } } @@ -127,25 +80,8 @@ class ErrorBoundary extends Component { }); }; - tryAgain = async () => { - // Only clear error logs in non-production environments - if (process.env.NODE_ENV !== 'production') { - try { - const response = await fetch('/api/logError', { - method: 'DELETE', - }); - - const data = await response.json(); - logger.debug('Error logs cleared:', data); - } catch (e) { - logger.error( - 'Failed to clear error logs:', - e instanceof Error ? e : { error: e }, - ); - } - } - - // Always reset the error state (needed for UI recovery) + tryAgain = () => { + // Reset the error state (needed for UI recovery) this.setState({ hasError: false }); };