20
20
21
21
import logging
22
22
from json import JSONDecodeError
23
- from typing import Any , Optional , Generator , Mapping , Tuple
23
+ from typing import Any , Optional , Generator , Mapping , Tuple , Union
24
24
25
25
from aiohttp import ClientResponse
26
26
from requests import Response
@@ -41,6 +41,12 @@ def _iter_json_messages(json: Any) -> Generator[str, None, None]:
41
41
yield message
42
42
43
43
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
+
44
50
class RPResponse :
45
51
"""Class representing ReportPortal API response."""
46
52
@@ -83,8 +89,7 @@ def json(self) -> Any:
83
89
try :
84
90
self .__json = self ._resp .json ()
85
91
except (JSONDecodeError , TypeError ) as exc :
86
- logger .warning ('Unable to decode JSON response, please check your endpoint configuration or API '
87
- 'key' , exc_info = exc )
92
+ logger .warning (_get_json_decode_error_message (self ._resp ), exc_info = exc )
88
93
self .__json = None
89
94
return self .__json
90
95
@@ -152,8 +157,7 @@ async def json(self) -> Any:
152
157
try :
153
158
self .__json = await self ._resp .json ()
154
159
except (JSONDecodeError , TypeError ) as exc :
155
- logger .warning ('Unable to decode JSON response, please check your endpoint configuration or API '
156
- 'key' , exc_info = exc )
160
+ logger .warning (_get_json_decode_error_message (self ._resp ), exc_info = exc )
157
161
self .__json = None
158
162
return self .__json
159
163
0 commit comments