Skip to content

Commit

Permalink
fix(graphql): GraphQL queries can exceed the rate limit even with x-r…
Browse files Browse the repository at this point in the history
…atelimit-remaining !== 0. (#636)
  • Loading branch information
jyasskin authored Oct 25, 2023
1 parent 39c0080 commit 94da99a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
7 changes: 5 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,11 @@ export function throttling(octokit: Octokit, octokitOptions: OctokitOptions) {
return { wantRetry, retryAfter };
}
if (
error.response.headers != null &&
error.response.headers["x-ratelimit-remaining"] === "0"
(error.response.headers != null &&
error.response.headers["x-ratelimit-remaining"] === "0") ||
(error.response.data?.errors ?? []).some(
(error: any) => error.type === "RATE_LIMITED",
)
) {
// The user has used all their allowed calls for the current time period (REST and GraphQL)
// https://docs.github.com/en/rest/reference/rate-limit (REST)
Expand Down
6 changes: 4 additions & 2 deletions test/retry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,9 @@ describe("Retry", function () {
{
status: 200,
headers: {
"x-ratelimit-remaining": "0",
// should retry based on response body, not header
// https://github.com/octokit/plugin-throttling.js/issues/632
"x-ratelimit-remaining": "1",
"x-ratelimit-reset": "123",
},
data: { errors: [{ type: "RATE_LIMITED" }] },
Expand Down Expand Up @@ -300,7 +302,7 @@ describe("Retry", function () {
{
status: 200,
headers: {
"x-ratelimit-remaining": "0",
"x-ratelimit-remaining": "1",
"x-ratelimit-reset": "123",
},
data: { errors: [{ type: "RATE_LIMITED" }] },
Expand Down

0 comments on commit 94da99a

Please sign in to comment.