Skip to content

Commit ea6ed04

Browse files
rwood-97claude
andcommitted
Fix GraphQL error handling: centralise in request_github_graphql
GraphQL errors come back as HTTP 200 with an "errors" key, bypassing the status code check. Added a check in request_github_graphql so all callers get consistent error handling, and removed the now-redundant ad-hoc check in licences.py. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 0261a3e commit ea6ed04

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

src/github_analyser/licences.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,6 @@ def get_licence(
3939
query = _get_licence_query(org_name, repo_name)
4040

4141
response = request_github_graphql({"query": query})
42-
# extract repo id from the first response
43-
if "errors" in response:
44-
print(f"Failed to get licence data for {repo_name}: {response['errors']}")
45-
return pd.Series()
46-
4742
repo_id = response["data"]["repository"]["id"]
4843
repo_url = response["data"]["repository"]["url"]
4944
licence_info = response["data"]["repository"]["licenseInfo"]

src/github_analyser/utils.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,11 @@ def request_github_graphql(payload: Any, headers: Any | None = None) -> Any:
7676
if response.status_code != 200:
7777
msg = f"GitHub query failed by code {response.status_code}."
7878
raise Exception(msg)
79-
return response.json()
79+
data = response.json()
80+
if "errors" in data:
81+
msg = f"GitHub GraphQL query returned errors: {data['errors']}"
82+
raise Exception(msg)
83+
return data
8084

8185

8286
def query_with_pagination(

0 commit comments

Comments
 (0)