Skip to content

Commit 7188d40

Browse files
committed
Better handle malformed responses
1 parent bea26c6 commit 7188d40

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

devstats/query.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,13 @@ def get_all_responses(query, query_type, headers):
127127

128128
print("Fetching...", end="", flush=True)
129129
rdata = send_query(query, query_type, headers, cursor=last_cursor)
130-
ratelimit_remaining = int(rdata["x-ratelimit-remaining"])
131-
pdata, last_cursor, total_count = parse_single_query(rdata, query_type)
130+
try:
131+
pdata, last_cursor, total_count = parse_single_query(rdata, query_type)
132+
except KeyError:
133+
print("Malformed response; repeating request")
134+
continue
132135
data.extend(pdata)
136+
ratelimit_remaining = int(rdata["x-ratelimit-remaining"])
133137
print(
134138
f"OK [{len(data)}/{total_count}] [ratelimit: {ratelimit_remaining}]",
135139
flush=True,
@@ -152,7 +156,7 @@ def parse_single_query(data, query_type):
152156
data = data["data"]["repository"][query_type]["edges"]
153157
last_cursor = data[-1]["cursor"]
154158
except KeyError as e:
155-
print(data)
159+
print(f"Error parsing response: {data}")
156160
raise e
157161
return data, last_cursor, total_count
158162

0 commit comments

Comments
 (0)