From 13a84efda4db5fae95e3c1414157187ba84f80a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartosz=20W=C3=B3jtowicz?= Date: Thu, 11 Jun 2026 09:49:33 +0200 Subject: [PATCH] Stop re-wrapping APIError as RequestError in AsyncSession 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. --- mwapi/async_session.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/mwapi/async_session.py b/mwapi/async_session.py index c02f0ee..4fa92ad 100644 --- a/mwapi/async_session.py +++ b/mwapi/async_session.py @@ -112,6 +112,11 @@ async def _request(self, method, params=None, auth=None): raise ConnectionError(str(e)) from e except aiohttp.TooManyRedirects as e: raise TooManyRedirectsError(str(e)) from e + except APIError: + # Raised above for a JSON 'error' response. Let it propagate with its + # structured .code/.info/.content instead of re-wrapping as RequestError + # below (matches the synchronous Session, which raises it uncaught). + raise except Exception as e: raise RequestError(str(e)) from e