Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle JSON decode errors in async client #75

Merged
merged 2 commits into from
Feb 20, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions uit/async_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,16 @@ async def call(
else:
return "ERROR! Gateway Timeout"

resp = await r.json()
try:
resp = await r.json()
except aiohttp.client_exceptions.ContentTypeError as e:
logger.error(
"JSON Parse Error '%s' - Status code: %s Content: %s",
str(e),
r.status,
await r.text(),
)
raise

if full_response:
return resp
Expand Down Expand Up @@ -328,7 +337,17 @@ async def put_file(self, local_path, remote_path=None, timeout=30):
raise UITError("Request Timeout")
logger.debug(await self._debug_uit(locals()))

return await r.json()
try:
return await r.json()
except aiohttp.client_exceptions.ContentTypeError as e:
# UIT should always return JSON, but other services may return an HTML error
logger.error(
"JSON Parse Error '%s' - Status code: %s Content: %s",
str(e),
r.status,
await r.text(),
)
raise UITError("Upload error") from e

@_ensure_connected
@robust()
Expand Down