@@ -261,34 +261,29 @@ def _make_request(
261261 raise RequestError ("Connection pool not initialized" , None )
262262
263263 try :
264- response = self ._pool .request (
264+ with self ._pool .request (
265265 method = method .upper (),
266266 url = path ,
267267 body = body ,
268268 headers = headers ,
269269 preload_content = False ,
270270 retries = self .retry_policy ,
271- )
271+ ) as response :
272+ # Handle successful responses
273+ if 200 <= response .status < 300 :
274+ return response .json ()
275+
276+ error_message = f"SEA HTTP request failed with status { response .status } "
277+ raise Exception (error_message )
272278 except MaxRetryError as e :
273279 # urllib3 MaxRetryError should bubble up for redirect tests to catch
274280 logger .error (f"SEA HTTP request failed with MaxRetryError: { e } " )
275281 raise
276282 except Exception as e :
277283 logger .error (f"SEA HTTP request failed with exception: { e } " )
278284 error_message = f"Error during request to server. { e } "
279- # Construct RequestError with proper 3-argument format (message, context, error)
280285 raise RequestError (error_message , None , None , e )
281286
282- logger .debug (f"Response status: { response .status } " )
283-
284- # Handle successful responses
285- if 200 <= response .status < 300 :
286- return response .json ()
287-
288- error_message = f"SEA HTTP request failed with status { response .status } "
289-
290- raise RequestError (error_message , None )
291-
292287 def _get_command_type_from_path (self , path : str , method : str ) -> CommandType :
293288 """
294289 Determine the command type based on the API path and method.
0 commit comments