Skip to content

Commit 67905af

Browse files
authored
Merge pull request #56 from OpenRailAssociation/graphql-better-debug
2 parents 192fdad + b0a3ec9 commit 67905af

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

gh_org_mgr/_gh_api.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,22 @@ def run_graphql_query(query, variables, token):
3939
headers=headers,
4040
timeout=10,
4141
)
42-
if request.status_code == 200:
43-
return request.json()
4442

45-
sys.exit(f"Query failed to run by returning code of {query}: {request.status_code}")
43+
# Get JSON result
44+
json_return = "No valid JSON return"
45+
try:
46+
json_return = request.json()
47+
except requests.exceptions.JSONDecodeError:
48+
pass
49+
50+
if request.status_code == 200:
51+
return json_return
52+
53+
# Debug information in case of errors
54+
print(
55+
f"Query failed with HTTP error code '{request.status_code}' when running "
56+
f"this query: {query}\n"
57+
f"Return: {json_return}\n"
58+
f"Headers: {request.headers}"
59+
)
60+
sys.exit(1)

0 commit comments

Comments
 (0)