diff --git a/backend/app/api/routers/chat.py b/backend/app/api/routers/chat.py index 9d714bf..3ca059b 100644 --- a/backend/app/api/routers/chat.py +++ b/backend/app/api/routers/chat.py @@ -97,6 +97,15 @@ async def send_message( except ValueError as exc: # AI not configured raise HTTPException(status_code=status.HTTP_422_UNPROCESSABLE_ENTITY, detail=str(exc)) + except Exception as exc: + error_msg = str(exc) + # Extract meaningful error from OpenAI exceptions + if hasattr(exc, 'message'): + error_msg = exc.message + elif hasattr(exc, 'body') and isinstance(exc.body, dict): + error_msg = exc.body.get('error', {}).get('message', error_msg) + logger.error("Chat error: %s", error_msg) + raise HTTPException(status_code=500, detail=f"AI error: {error_msg[:500]}") except Exception as exc: logger.exception("Chat error for user %s", user.id) raise HTTPException(