Skip to content

Commit 646b7bf

Browse files
elderingvmcj
authored andcommitted
Show the raw response if JSON decoding fails.
This may happen for example when PHP runs out of memory. (cherry picked from commit 1c297a5)
1 parent dbc1128 commit 646b7bf

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

misc-tools/dj_utils.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,13 @@ def parse_api_response(name: str, response: requests.Response):
4444
return None
4545

4646
# We got a successful HTTP response. It worked. Return the full response
47-
return json.loads(response.text)
47+
try:
48+
result = json.loads(response.text)
49+
except json.decoder.JSONDecodeError as e:
50+
print(response.text)
51+
raise RuntimeError(f'Failed to JSON decode the response for API request {name}')
52+
53+
return result
4854

4955

5056
def do_api_request(name: str, method: str = 'GET', jsonData: dict = {}):

0 commit comments

Comments
 (0)