@@ -93,15 +93,23 @@ def follow_redirect(request, status:, response_headers:)
9393 URI . join ( url , response_headers [ "location" ] )
9494 rescue ArgumentError
9595 message = "Server responded with status #{ status } but no valid location header."
96- raise OpenAI ::Errors ::APIConnectionError . new ( url : url , message : message )
96+ raise OpenAI ::Errors ::APIConnectionError . new (
97+ url : url ,
98+ response : response_headers ,
99+ message : message
100+ )
97101 end
98102
99103 request = { **request , url : location }
100104
101105 case [ url . scheme , location . scheme ]
102106 in [ "https" , "http" ]
103107 message = "Tried to redirect to a insecure URL"
104- raise OpenAI ::Errors ::APIConnectionError . new ( url : url , message : message )
108+ raise OpenAI ::Errors ::APIConnectionError . new (
109+ url : url ,
110+ response : response_headers ,
111+ message : message
112+ )
105113 else
106114 nil
107115 end
@@ -350,7 +358,7 @@ def initialize(
350358 self . class . reap_connection! ( status , stream : stream )
351359
352360 message = "Failed to complete the request within #{ self . class ::MAX_REDIRECTS } redirects."
353- raise OpenAI ::Errors ::APIConnectionError . new ( url : url , message : message )
361+ raise OpenAI ::Errors ::APIConnectionError . new ( url : url , response : response , message : message )
354362 in 300 ..399
355363 self . class . reap_connection! ( status , stream : stream )
356364
0 commit comments