@@ -174,15 +174,13 @@ def on_response(
174174 kind = FieldPosition .HEADER ,
175175 )
176176
177- response = AWSCRTHTTPResponse (
178- status = status_code ,
179- fields = fields ,
180- body = self ._body ,
181- )
182- if status_code != 200 and status_code >= 300 :
183- self ._response_future .set_exception (CRTErrorResponse (response ))
184- else :
185- self ._response_future .set_result (response )
177+ self ._response_future .set_result (
178+ AWSCRTHTTPResponse (
179+ status = status_code ,
180+ fields = fields ,
181+ body = self ._body ,
182+ )
183+ )
186184
187185 async def await_response (self ) -> AWSCRTHTTPResponse :
188186 return await asyncio .wrap_future (self ._response_future )
@@ -195,18 +193,6 @@ def _cancel(self, completion_future: ConcurrentFuture[int | Exception]) -> None:
195193 self ._response_future .cancel ()
196194
197195
198- class CRTErrorResponse (Exception ):
199- def __init__ (self , response : AWSCRTHTTPResponse ) -> None :
200- self ._status = response .status
201- self ._response = response
202-
203- super ().__init__ (f"Request failed with status code { self ._status } " )
204-
205- @property
206- def response (self ) -> AWSCRTHTTPResponse :
207- return self ._response
208-
209-
210196ConnectionPoolKey = tuple [str , str , int | None ]
211197ConnectionPoolDict = dict [ConnectionPoolKey , "crt_http.HttpClientConnection" ]
212198
@@ -265,11 +251,12 @@ async def send(
265251 crt_stream .completion_future .add_done_callback (
266252 partial (self ._close_input_body , body = crt_body )
267253 )
268- try :
269- return await response_factory .await_response ()
270- except CRTErrorResponse as e :
254+
255+ response = await response_factory .await_response ()
256+ if response . status != 200 and response . status >= 300 :
271257 await close (crt_body )
272- return e .response
258+
259+ return response
273260
274261 def _close_input_body (
275262 self , future : ConcurrentFuture [int ], * , body : "BufferableByteStream | BytesIO"
0 commit comments