diff --git a/uit/async_client.py b/uit/async_client.py index 4606f73..da74389 100644 --- a/uit/async_client.py +++ b/uit/async_client.py @@ -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 @@ -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()