Skip to content

Commit

Permalink
Merge pull request #56 from OpenRailAssociation/graphql-better-debug
Browse files Browse the repository at this point in the history
  • Loading branch information
mxmehl authored Nov 26, 2024
2 parents 192fdad + b0a3ec9 commit 67905af
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions gh_org_mgr/_gh_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,22 @@ def run_graphql_query(query, variables, token):
headers=headers,
timeout=10,
)
if request.status_code == 200:
return request.json()

sys.exit(f"Query failed to run by returning code of {query}: {request.status_code}")
# Get JSON result
json_return = "No valid JSON return"
try:
json_return = request.json()
except requests.exceptions.JSONDecodeError:
pass

if request.status_code == 200:
return json_return

# Debug information in case of errors
print(
f"Query failed with HTTP error code '{request.status_code}' when running "
f"this query: {query}\n"
f"Return: {json_return}\n"
f"Headers: {request.headers}"
)
sys.exit(1)

0 comments on commit 67905af

Please sign in to comment.