2020
2121import logging
2222from json import JSONDecodeError
23- from typing import Any , Optional , Generator , Mapping , Tuple
23+ from typing import Any , Optional , Generator , Mapping , Tuple , Union
2424
2525from aiohttp import ClientResponse
2626from requests import Response
@@ -41,6 +41,12 @@ def _iter_json_messages(json: Any) -> Generator[str, None, None]:
4141 yield message
4242
4343
44+ def _get_json_decode_error_message (response : Union [Response , ClientResponse ]) -> str :
45+ status = getattr (response , 'status' , getattr (response , 'status_code' ))
46+ return f'Unable to decode JSON response, got { "passed" if response .ok else "failed" } ' \
47+ f'response with code "{ status } " please check your endpoint configuration or API key'
48+
49+
4450class RPResponse :
4551 """Class representing ReportPortal API response."""
4652
@@ -82,7 +88,8 @@ def json(self) -> Any:
8288 if self .__json is NOT_SET :
8389 try :
8490 self .__json = self ._resp .json ()
85- except (JSONDecodeError , TypeError ):
91+ except (JSONDecodeError , TypeError ) as exc :
92+ logger .error (_get_json_decode_error_message (self ._resp ), exc_info = exc )
8693 self .__json = None
8794 return self .__json
8895
@@ -149,7 +156,8 @@ async def json(self) -> Any:
149156 if self .__json is NOT_SET :
150157 try :
151158 self .__json = await self ._resp .json ()
152- except (JSONDecodeError , TypeError ):
159+ except (JSONDecodeError , TypeError ) as exc :
160+ logger .error (_get_json_decode_error_message (self ._resp ), exc_info = exc )
153161 self .__json = None
154162 return self .__json
155163
0 commit comments