From 77a867853b9c385d13a2afd5f0eb9e416e511c6c Mon Sep 17 00:00:00 2001 From: Willy Douhard Date: Mon, 3 Jun 2024 15:57:41 +0200 Subject: [PATCH] fix: log json parse errors --- literalai/api/__init__.py | 32 ++++++++++++++++++++++++-------- literalai/version.py | 2 +- setup.py | 2 +- 3 files changed, 26 insertions(+), 10 deletions(-) diff --git a/literalai/api/__init__.py b/literalai/api/__init__.py index 7946fbc..7a47546 100644 --- a/literalai/api/__init__.py +++ b/literalai/api/__init__.py @@ -195,7 +195,12 @@ def raise_error(error): except httpx.HTTPStatusError: raise_error(f"Failed to {description}: {response.text}") - json = response.json() + try: + json = response.json() + except ValueError as e: + raise_error( + f"Failed to parse JSON response: {e}, content: {response.content!r}" + ) if json.get("errors"): raise_error(json["errors"]) @@ -240,9 +245,12 @@ def make_rest_call(self, subpath: str, body: Dict[str, Any]) -> Dict: logger.error(message) raise Exception(message) - json = response.json() - - return json + try: + return response.json() + except ValueError as e: + raise ValueError( + f"Failed to parse JSON response: {e}, content: {response.content!r}" + ) def gql_helper( self, @@ -1377,7 +1385,12 @@ def raise_error(error): except httpx.HTTPStatusError: raise_error(f"Failed to {description}: {response.text}") - json = response.json() + try: + json = response.json() + except ValueError as e: + raise_error( + f"Failed to parse JSON response: {e}, content: {response.content!r}" + ) if json.get("errors"): raise_error(json["errors"]) @@ -1422,9 +1435,12 @@ async def make_rest_call(self, subpath: str, body: Dict[str, Any]) -> Dict: logger.error(message) raise Exception(message) - json = response.json() - - return json + try: + return response.json() + except ValueError as e: + raise ValueError( + f"Failed to parse JSON response: {e}, content: {response.content!r}" + ) async def gql_helper( self, diff --git a/literalai/version.py b/literalai/version.py index 3c002da..6eadab0 100644 --- a/literalai/version.py +++ b/literalai/version.py @@ -1 +1 @@ -__version__ = "0.0.605" +__version__ = "0.0.606" diff --git a/setup.py b/setup.py index f37c26f..a1eb746 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ setup( name="literalai", - version="0.0.605", # update version in literalai/version.py + version="0.0.606", # update version in literalai/version.py description="An SDK for observability in Python applications", author="Literal AI", package_data={"literalai": ["py.typed"]},