Skip to content

Commit 94da99a

Browse files
authoredOct 25, 2023
fix(graphql): GraphQL queries can exceed the rate limit even with x-ratelimit-remaining !== 0. (#636)
1 parent 39c0080 commit 94da99a

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed
 

‎src/index.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,11 @@ export function throttling(octokit: Octokit, octokitOptions: OctokitOptions) {
137137
return { wantRetry, retryAfter };
138138
}
139139
if (
140-
error.response.headers != null &&
141-
error.response.headers["x-ratelimit-remaining"] === "0"
140+
(error.response.headers != null &&
141+
error.response.headers["x-ratelimit-remaining"] === "0") ||
142+
(error.response.data?.errors ?? []).some(
143+
(error: any) => error.type === "RATE_LIMITED",
144+
)
142145
) {
143146
// The user has used all their allowed calls for the current time period (REST and GraphQL)
144147
// https://docs.github.com/en/rest/reference/rate-limit (REST)

‎test/retry.test.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,9 @@ describe("Retry", function () {
250250
{
251251
status: 200,
252252
headers: {
253-
"x-ratelimit-remaining": "0",
253+
// should retry based on response body, not header
254+
// https://github.com/octokit/plugin-throttling.js/issues/632
255+
"x-ratelimit-remaining": "1",
254256
"x-ratelimit-reset": "123",
255257
},
256258
data: { errors: [{ type: "RATE_LIMITED" }] },
@@ -300,7 +302,7 @@ describe("Retry", function () {
300302
{
301303
status: 200,
302304
headers: {
303-
"x-ratelimit-remaining": "0",
305+
"x-ratelimit-remaining": "1",
304306
"x-ratelimit-reset": "123",
305307
},
306308
data: { errors: [{ type: "RATE_LIMITED" }] },

0 commit comments

Comments
 (0)
Please sign in to comment.