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 return
except Exception as e: 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 ( yield (
"data: " "data: "
+ json.dumps( + json.dumps(
{ {
"type": "error", "type": "error",
"message": "An error occurred while processing your request.", "message": f"An error occurred while processing your request: {error_msg}",
} }
) )
+ "\n\n" + "\n\n"

View file

@ -67,10 +67,12 @@ async def post_chat_message_stream(
) )
except Exception as e: 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( raise HTTPException(
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, 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 return response
except ValueError as e: except ValueError as e:
logger.error(f"Permission error: {str(e)}") logger.error(f"Permission error: {str(e)}", exc_info=True)
raise HTTPException( raise HTTPException(
status_code=status.HTTP_403_FORBIDDEN, status_code=status.HTTP_403_FORBIDDEN,
detail=str(e), detail=str(e) or "Permission denied",
) )
except Exception as e: 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( raise HTTPException(
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, 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) return ThreadListResponse(threads=dummy_threads)
except Exception as e: 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( raise HTTPException(
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, 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: 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( raise HTTPException(
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, 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: 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( raise HTTPException(
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, 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'}",
) )