Stop re-wrapping APIError as RequestError in AsyncSession#49
Open
BartWojtowicz wants to merge 1 commit into
Open
Stop re-wrapping APIError as RequestError in AsyncSession#49BartWojtowicz wants to merge 1 commit into
BartWojtowicz wants to merge 1 commit into
Conversation
The synchronous Session raises APIError outside its request try/except, so it reaches callers with .code/.info/.content intact. AsyncSession._request raised it inside the try whose catch-all `except Exception` re-wrapped it as a generic RequestError, discarding those structured attributes. Re-raise APIError before the catch-all so async callers can inspect the API error code, matching the synchronous Session.
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.
AsyncSession._requestraisesAPIError.from_doc(...)(Lines 91-92), but it later gets re-wrapped as genericRequestErrorinside the try/except block, which means we are losing the structured.code/.info/.contentattributes.This is not ideal, because callers have to parse the
RequestErrorstring to inspect the error, rather than using theAPIErrorresponse.This problem only exists within the async
_requestcall. The synchronous version raisesAPIErrorafter the try/except block so it reaches callers nicely. This change makes the async version of the code match this behaviour. Additionally, our async docstring states thatRaises: APIError if the API responds with an error, which is currently not true due to this bug.