Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ export function throttling(octokit: Octokit, octokitOptions = {}) {
options.request.retryCount = retryCount;

const { wantRetry, retryAfter } = await (async function () {
if (/\babuse\b/i.test(error.message)) {
if (/\bsecondary rate\b/i.test(error.message)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tests need to be updated. I can do that if you are busy, just let me know.

Do you by chance have the full response error object available, with both the response body and headers?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you can take care of updating the tests, that'd be great - thanks!

here is the full error log (this was from a graphql request generated by https://github.com/w3c/validate-repos):

  status: 403,
  response: {
    url: 'https://api.github.com/graphql',
    status: 403,
    headers: {
      'access-control-allow-origin': '*',
      'access-control-expose-headers': 'ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Used, X-RateLimit-Resource, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, Deprecation, Sunset',
      connection: 'close',
      'content-encoding': 'gzip',
      'content-security-policy': "default-src 'none'; base-uri 'self'; block-all-mixed-content; connect-src 'self' uploads.github.com www.githubstatus.com collector.githubapp.com api.github.com github-cloud.s3.amazonaws.com github-production-repository-file-5c1aeb.s3.amazonaws.com github-production-upload-manifest-file-7fdce7.s3.amazonaws.com github-production-user-asset-6210df.s3.amazonaws.com cdn.optimizely.com logx.optimizely.com/v1/events translator.github.com; font-src github.githubassets.com; form-action 'self' github.com gist.github.com; frame-ancestors 'none'; frame-src render.githubusercontent.com viewscreen.githubusercontent.com; img-src 'self' data: github.githubassets.com media.githubusercontent.com camo.githubusercontent.com identicons.github.com collector.githubapp.com avatars.githubusercontent.com github-cloud.s3.amazonaws.com secured-user-images.githubusercontent.com/; manifest-src 'self'; media-src 'none'; script-src github.githubassets.com; style-src 'unsafe-inline' github.githubassets.com",
      'content-type': 'application/json; charset=utf-8',
      date: 'Mon, 06 Sep 2021 12:04:35 GMT',
      'expect-ct': 'max-age=2592000, report-uri="https://api.github.com/_private/browser/errors"',
      'referrer-policy': 'origin-when-cross-origin, strict-origin-when-cross-origin',
      'retry-after': '60',
      server: 'GitHub.com',
      'strict-transport-security': 'max-age=31536000; includeSubdomains; preload',
      'transfer-encoding': 'chunked',
      vary: 'Accept-Encoding, Accept, X-Requested-With',
      'x-content-type-options': 'nosniff',
      'x-frame-options': 'deny',
      'x-github-media-type': 'github.v4; format=json',
      'x-github-request-id': '[REDACTED]',
      'x-xss-protection': '0'
    },
    data: {
      documentation_url: 'https://docs.github.com/en/free-pro-team@latest/rest/overview/resources-in-the-rest-api#secondary-rate-limits',
      message: 'You have exceeded a secondary rate limit. Please wait a few minutes before you try again.'
    }
  },
  request: {
    method: 'POST',
    url: 'https://api.github.com/graphql',
    headers: {
      accept: 'application/vnd.github.v3+json',
      'user-agent': 'octokit-core.js/3.5.1 Node.js/12.22.6 (linux; x64)',
      authorization: 'token [REDACTED]',
      'content-type': 'application/json; charset=utf-8'
    },
    body: '{"query":"\\n  query ($org: String!, $cursor: String) {\\n    organization(login: $org) {\\n      repositories(first: 10, after: $cursor) {\\n        nodes {\\n          id\\n          name\\n          owner {\\n            login\\n          }\\n          isArchived\\n          homepageUrl\\n          description\\n          isPrivate\\n          createdAt\\n          labels(first: 100) {\\n            nodes {\\n              name\\n              color\\n            }\\n            pageInfo {\\n              endCursor\\n              hasNextPage\\n            }\\n          }\\n          defaultBranch: defaultBranchRef {\\n            name\\n          }\\n          branchProtectionRules(first: 5) {\\n            nodes {\\n              pattern\\n              requiredApprovingReviewCount\\n              requiredStatusCheckContexts\\n              isAdminEnforced\\n            }\\n          }\\n          w3cjson: object(expression: \\"HEAD:w3c.json\\") {\\n            ... on Blob {\\n              text\\n            }\\n          }\\n          prpreviewjson: object(expression: \\"HEAD:.pr-preview.json\\") {\\n            ... on Blob {\\n              text\\n            }\\n          }\\n          autoPublish: object(expression: \\"HEAD:.github/workflows/auto-publish.yml\\") {\\n            ... on Blob {\\n              text\\n            }\\n          }\\n          travis: object(expression: \\"HEAD:.travis.yml\\") {\\n            ... on Blob {\\n              text\\n            }\\n          }\\n          contributing: object(expression: \\"HEAD:CONTRIBUTING.md\\") {\\n            ... on Blob {\\n              text\\n            }\\n          }\\n          license: object(expression: \\"HEAD:LICENSE.md\\") {\\n            ... on Blob {\\n              text\\n            }\\n          }\\n          codeOfConduct {\\n            body\\n          }\\n          readme: object(expression: \\"HEAD:README.md\\") {\\n            ... on Blob {\\n              text\\n            }\\n          }\\n        }\\n        pageInfo {\\n          endCursor\\n          hasNextPage\\n        }\\n      }\\n    }\\n  }\\n","variables":{"org":"w3c","cursor":"Y3Vyc29yOnYyOpHOB8UmtA=="}}',
    request: { hook: [Function: bound bound register] }
  }

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, thank you!

// The user has hit the abuse rate limit. (REST and GraphQL)
// https://docs.github.com/en/rest/overview/resources-in-the-rest-api#abuse-rate-limits

Expand Down
6 changes: 3 additions & 3 deletions test/events.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ describe("Events", function () {
status: 403,
headers: { "retry-after": "60" },
data: {
message: "You have been rate limited to prevent abuse",
message: "You have exceeded a secondary rate limit",
},
},
],
Expand Down Expand Up @@ -112,7 +112,7 @@ describe("Events", function () {
status: 403,
headers: { "retry-after": "2" },
data: {
message: "You have been rate limited to prevent abuse",
message: "You have exceeded a secondary rate limit",
},
},
],
Expand Down Expand Up @@ -156,7 +156,7 @@ describe("Events", function () {
status: 403,
headers: {},
data: {
message: "You have been rate limited to prevent abuse",
message: "You have exceeded a secondary rate limit",
},
},
],
Expand Down
6 changes: 3 additions & 3 deletions test/retry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe("Retry", function () {
{
status: 403,
headers: { "retry-after": "1" },
data: { message: "You have been rate limited to prevent abuse" },
data: { message: "You have exceeded a secondary rate limit" },
},
{ status: 200, headers: {}, data: { message: "Success!" } },
],
Expand Down Expand Up @@ -69,7 +69,7 @@ describe("Retry", function () {
},
});

const message = "You have been rate limited to prevent abuse";
const message = "You have exceeded a secondary rate limit";
try {
await octokit.request("GET /route", {
request: {
Expand Down Expand Up @@ -366,7 +366,7 @@ describe("Retry", function () {
},
data: {
message:
"You have triggered an abuse detection mechanism. Please wait a few minutes before you try again.",
"You have exceeded a secondary rate limit. Please wait a few minutes before you try again.",
documentation_url:
"https://developer.github.com/v3/#abuse-rate-limits",
},
Expand Down