chore: better error messages

This commit is contained in:
Christopher Gondek 2025-10-06 15:05:22 +02:00
parent d33241e5dc
commit 33f8ff1b5e
2 changed files with 27 additions and 14 deletions

View file

@ -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"

View file

@ -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'}",
)