Skip to content

Stop re-wrapping APIError as RequestError in AsyncSession#49

Open
BartWojtowicz wants to merge 1 commit into
mediawiki-utilities:masterfrom
BartWojtowicz:fix-async-apierror-not-rewrapped
Open

Stop re-wrapping APIError as RequestError in AsyncSession#49
BartWojtowicz wants to merge 1 commit into
mediawiki-utilities:masterfrom
BartWojtowicz:fix-async-apierror-not-rewrapped

Conversation

@BartWojtowicz

Copy link
Copy Markdown

AsyncSession._request raises APIError.from_doc(...) (Lines 91-92), but it later gets re-wrapped as generic RequestError inside the try/except block, which means we are losing the structured .code / .info / .content attributes.
This is not ideal, because callers have to parse the RequestError string to inspect the error, rather than using the APIError response.

This problem only exists within the async _request call. The synchronous version raises APIError after 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 that Raises: APIError if the API responds with an error, which is currently not true due to this bug.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant