-
Notifications
You must be signed in to change notification settings - Fork 24
Close request when initial response fails and propagate error #454
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -174,13 +174,15 @@ def on_response( | |
| kind=FieldPosition.HEADER, | ||
| ) | ||
|
|
||
| self._response_future.set_result( | ||
| AWSCRTHTTPResponse( | ||
| status=status_code, | ||
| fields=fields, | ||
| body=self._body, | ||
| ) | ||
| response = AWSCRTHTTPResponse( | ||
| status=status_code, | ||
| fields=fields, | ||
| body=self._body, | ||
| ) | ||
| if status_code != 200 and status_code >= 300: | ||
| self._response_future.set_exception(CRTErrorResponse(response)) | ||
| else: | ||
| self._response_future.set_result(response) | ||
|
|
||
| async def await_response(self) -> AWSCRTHTTPResponse: | ||
| return await asyncio.wrap_future(self._response_future) | ||
|
|
@@ -193,6 +195,18 @@ def _cancel(self, completion_future: ConcurrentFuture[int | Exception]) -> None: | |
| self._response_future.cancel() | ||
|
|
||
|
|
||
| class CRTErrorResponse(Exception): | ||
alextwoods marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| def __init__(self, response: AWSCRTHTTPResponse) -> None: | ||
| self._status = response.status | ||
| self._response = response | ||
|
|
||
| super().__init__(f"Request failed with status code {self._status}") | ||
alextwoods marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| @property | ||
| def response(self) -> AWSCRTHTTPResponse: | ||
| return self._response | ||
|
||
|
|
||
|
|
||
| ConnectionPoolKey = tuple[str, str, int | None] | ||
| ConnectionPoolDict = dict[ConnectionPoolKey, "crt_http.HttpClientConnection"] | ||
|
|
||
|
|
@@ -251,7 +265,11 @@ async def send( | |
| crt_stream.completion_future.add_done_callback( | ||
| partial(self._close_input_body, body=crt_body) | ||
| ) | ||
| return await response_factory.await_response() | ||
| try: | ||
| return await response_factory.await_response() | ||
| except CRTErrorResponse as e: | ||
| await close(crt_body) | ||
| return e.response | ||
alextwoods marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| def _close_input_body( | ||
| self, future: ConcurrentFuture[int], *, body: "BufferableByteStream | BytesIO" | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.