diff --git a/backend/alwrity_utils/router_manager.py b/backend/alwrity_utils/router_manager.py index 6e13155a..769e6443 100644 --- a/backend/alwrity_utils/router_manager.py +++ b/backend/alwrity_utils/router_manager.py @@ -91,6 +91,10 @@ class RouterManager: from api.content_planning.strategy_copilot import router as strategy_copilot_router self.include_router_safely(strategy_copilot_router, "strategy_copilot") + # Error logging router + from routers.error_logging import router as error_logging_router + self.include_router_safely(error_logging_router, "error_logging") + logger.info("✅ Core routers included successfully") return True diff --git a/backend/routers/error_logging.py b/backend/routers/error_logging.py new file mode 100644 index 00000000..e4e68351 --- /dev/null +++ b/backend/routers/error_logging.py @@ -0,0 +1,50 @@ +""" +Error Logging Router +Provides endpoints for frontend error reporting +""" +from fastapi import APIRouter, HTTPException +from pydantic import BaseModel +from typing import Optional +import logging + +router = APIRouter() +logger = logging.getLogger(__name__) + +class ErrorLogRequest(BaseModel): + error_message: str + error_stack: Optional[str] = None + component_stack: Optional[str] = None + user_id: Optional[str] = None + url: Optional[str] = None + user_agent: Optional[str] = None + timestamp: Optional[str] = None + additional_info: Optional[dict] = None + +@router.post("/log-error") +async def log_frontend_error(error_log: ErrorLogRequest): + """ + Log errors from the frontend for monitoring and debugging + """ + try: + # Log the error with all details + logger.error( + f"Frontend Error: {error_log.error_message}", + extra={ + "error_stack": error_log.error_stack, + "component_stack": error_log.component_stack, + "user_id": error_log.user_id, + "url": error_log.url, + "user_agent": error_log.user_agent, + "timestamp": error_log.timestamp, + "additional_info": error_log.additional_info + } + ) + + return { + "status": "success", + "message": "Error logged successfully" + } + except Exception as e: + logger.error(f"Failed to log frontend error: {str(e)}") + raise HTTPException(status_code=500, detail="Failed to log error") + diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index 849627b2..c34f23d4 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -228,28 +228,13 @@ const App: React.FC = () => { ); } - return ( - { - // Custom error handler - send to analytics/monitoring - console.error('Global error caught:', { error, errorInfo }); - // TODO: Send to error tracking service (Sentry, LogRocket, etc.) - }} - > - - - console.error("CopilotKit Error:", e)} - - > - - - - + // Render app with or without CopilotKit based on whether we have a key + const renderApp = () => { + const appContent = ( + + + + } /> { } /> } /> } /> - - - + + + + ); + + // Only wrap with CopilotKit if we have a valid key + if (copilotApiKey && copilotApiKey.trim()) { + return ( + console.error("CopilotKit Error:", e)} + > + {appContent} + ); + } + + // Return app without CopilotKit if no key available + return appContent; + }; + + return ( + { + // Custom error handler - send to analytics/monitoring + console.error('Global error caught:', { error, errorInfo }); + // TODO: Send to error tracking service (Sentry, LogRocket, etc.) + }} + > + + + {renderApp()}