fix: guard against non-dict JSON in token refresh response

resp.json() could return non-dict values (null, string, list) which
would cause AttributeError on data.get("access_token"). Now checks
isinstance(data, dict) first, returning (False, None) for malformed
responses. Applied to both sync and async refresh helpers.
This commit is contained in:
Ejiro Asiuwhu 2026-03-26 10:52:22 +01:00
parent b44fabc623
commit 6aaa4b3b4b

View File

@ -390,6 +390,8 @@ def _refresh_access_token_sync(
)
if resp.status_code == 200:
data = resp.json()
if not isinstance(data, dict):
return (False, None)
return (True, data.get("access_token"))
return (False, None)
except (httpx.HTTPError, ValueError, KeyError) as exc:
@ -421,6 +423,8 @@ async def _refresh_access_token_async(
)
if resp.status_code == 200:
data = resp.json()
if not isinstance(data, dict):
return (False, None)
return (True, data.get("access_token"))
return (False, None)
except (httpx.HTTPError, ValueError, KeyError) as exc: