Close request when initial response fails and propagate error#454
Merged
alextwoods merged 3 commits intosmithy-lang:developfrom Mar 19, 2025
Merged
Close request when initial response fails and propagate error#454alextwoods merged 3 commits intosmithy-lang:developfrom
alextwoods merged 3 commits intosmithy-lang:developfrom
Conversation
alextwoods
commented
Mar 19, 2025
nateprewitt
reviewed
Mar 19, 2025
Comment on lines
199
to
207
| def __init__(self, response: AWSCRTHTTPResponse) -> None: | ||
| self._status = response.status | ||
| self._response = response | ||
|
|
||
| super().__init__(f"Request failed with status code {self._status}") | ||
|
|
||
| @property | ||
| def response(self) -> AWSCRTHTTPResponse: | ||
| return self._response |
Contributor
There was a problem hiding this comment.
What actually gets surfaced to the end user with the stack trace here? Is it only the message being passed to the base Exception constructor? Ideally we have more context if we can.
Contributor
Author
There was a problem hiding this comment.
This exception gets caught in the AWSCRTHTTPClient.send method, which then closes the request body and returns the response upwards. The client code then deserializes the response using its deserializers and will create the appropriate service exception. An example for an expired security token:
Traceback (most recent call last):
File "/Users/alexwoo/python/test-lexruntime/lexruntime/client.py", line 595, in _execute_operation
return await self._handle_execution(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/alexwoo/python/test-lexruntime/lexruntime/client.py", line 751, in _handle_execution
return await self._finalize_execution(interceptor_chain, output_context)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/alexwoo/python/test-lexruntime/lexruntime/client.py", line 1003, in _finalize_execution
raise context.response
File "/Users/alexwoo/python/test-lexruntime/lexruntime/client.py", line 717, in _handle_execution
raise output_context.response
File "/Users/alexwoo/python/test-lexruntime/lexruntime/client.py", line 916, in _handle_attempt
output = await deserialize(response_context.transport_response, config)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/alexwoo/python/test-lexruntime/lexruntime/deserialize.py", line 403, in _deserialize_start_conversation
raise e
lexruntime.models.UnknownApiError: ExpiredTokenException: The security token included in the request is expired
JordonPhillips
requested changes
Mar 19, 2025
JordonPhillips
requested changes
Mar 19, 2025
JordonPhillips
approved these changes
Mar 19, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description of changes:
This fixes an issue where event stream initial response failures cause the stream to hang. There are two issues:
donemethod on the asyncio response_future and so were not setting the exception in it correclty.There may be better ways to ensure the request body gets closed on an error in initial request.
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.