@@ -348,3 +348,24 @@ def test_integration_with_retry_logic():
348348 assert exception_class in DEFAULT_RETRYABLE_EXCEPTIONS , (
349349 f"{ exception_class .__name__ } should be in DEFAULT_RETRYABLE_EXCEPTIONS for retry support"
350350 )
351+
352+
353+ def test_exception_message_preservation ():
354+ """Test that error messages are properly preserved in exceptions."""
355+ test_cases = [
356+ (13 , "test error" , InternalError ),
357+ (5 , "Model xyz not found" , NotFoundError ),
358+ (7 , "Invalid API key" , PermissionDeniedError ),
359+ ]
360+
361+ for status_code , message , expected_exception_class in test_cases :
362+ # Test with message
363+ exception = exception_for_status_code (status_code , message )
364+ assert exception is not None
365+ assert isinstance (exception , expected_exception_class )
366+ assert str (exception ) == message , f"Exception should preserve message '{ message } '"
367+
368+ # Test without message (should still work)
369+ exception_no_msg = exception_for_status_code (status_code )
370+ assert exception_no_msg is not None
371+ assert isinstance (exception_no_msg , expected_exception_class )
0 commit comments