diff --git a/modules/features/chatBot/service.py b/modules/features/chatBot/service.py index 1899d8e9..b88f1753 100644 --- a/modules/features/chatBot/service.py +++ b/modules/features/chatBot/service.py @@ -202,13 +202,14 @@ async def post_message_stream( return except Exception as e: - logger.error(f"Error in streaming chat: {str(e)}", exc_info=True) + error_msg = f"{type(e).__name__}: {str(e) or 'No error message provided'}" + logger.error(f"Error in streaming chat: {error_msg}", exc_info=True) yield ( "data: " + json.dumps( { "type": "error", - "message": "An error occurred while processing your request.", + "message": f"An error occurred while processing your request: {error_msg}", } ) + "\n\n" diff --git a/modules/routes/routeChatbot.py b/modules/routes/routeChatbot.py index 01617582..c0ee5bee 100644 --- a/modules/routes/routeChatbot.py +++ b/modules/routes/routeChatbot.py @@ -67,10 +67,12 @@ async def post_chat_message_stream( ) except Exception as e: - logger.error(f"Error posting chat message: {str(e)}") + logger.error( + f"Error posting chat message: {type(e).__name__}: {str(e)}", exc_info=True + ) raise HTTPException( status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, - detail=f"Failed to post message: {str(e)}", + detail=f"Failed to post message: {type(e).__name__}: {str(e) or 'No error message provided'}", ) @@ -103,16 +105,18 @@ async def post_chat_message( return response except ValueError as e: - logger.error(f"Permission error: {str(e)}") + logger.error(f"Permission error: {str(e)}", exc_info=True) raise HTTPException( status_code=status.HTTP_403_FORBIDDEN, - detail=str(e), + detail=str(e) or "Permission denied", ) except Exception as e: - logger.error(f"Error posting chat message: {str(e)}") + logger.error( + f"Error posting chat message: {type(e).__name__}: {str(e)}", exc_info=True + ) raise HTTPException( status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, - detail=f"Failed to post message: {str(e)}", + detail=f"Failed to post message: {type(e).__name__}: {str(e) or 'No error message provided'}", ) @@ -155,10 +159,12 @@ async def get_all_threads( return ThreadListResponse(threads=dummy_threads) except Exception as e: - logger.error(f"Error retrieving threads: {str(e)}") + logger.error( + f"Error retrieving threads: {type(e).__name__}: {str(e)}", exc_info=True + ) raise HTTPException( status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, - detail=f"Failed to retrieve threads: {str(e)}", + detail=f"Failed to retrieve threads: {type(e).__name__}: {str(e) or 'No error message provided'}", ) @@ -207,10 +213,13 @@ async def get_thread_by_id( ) except Exception as e: - logger.error(f"Error retrieving thread {thread_id}: {str(e)}") + logger.error( + f"Error retrieving thread {thread_id}: {type(e).__name__}: {str(e)}", + exc_info=True, + ) raise HTTPException( status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, - detail=f"Failed to retrieve thread: {str(e)}", + detail=f"Failed to retrieve thread: {type(e).__name__}: {str(e) or 'No error message provided'}", ) @@ -238,8 +247,11 @@ async def delete_thread( ) except Exception as e: - logger.error(f"Error deleting thread {thread_id}: {str(e)}") + logger.error( + f"Error deleting thread {thread_id}: {type(e).__name__}: {str(e)}", + exc_info=True, + ) raise HTTPException( status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, - detail=f"Failed to delete thread: {str(e)}", + detail=f"Failed to delete thread: {type(e).__name__}: {str(e) or 'No error message provided'}", )