Skip to content

Commit 8ab337a

Browse files
committed
Handle GitHub token errors
1 parent b9660cb commit 8ab337a

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

devstats/query.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import json
2+
import sys
23
import time
34

45
import requests
@@ -174,6 +175,13 @@ def parse_single_query(data, query_type):
174175
data = data["data"]["repository"][query_type]["edges"]
175176
last_cursor = data[-1]["cursor"]
176177
except (KeyError, TypeError) as e:
178+
if "errors" in data:
179+
errors = data["errors"]
180+
if errors:
181+
print("GitHub error:", errors[0]["message"])
182+
if errors[0]["type"] == "FORBIDDEN":
183+
print("Fatal: incorrect permissions; exiting")
184+
sys.exit(1)
177185
print(f"Error parsing response: {data}")
178186
raise e
179187
return data, last_cursor, total_count

0 commit comments

Comments
 (0)