diff --git a/assets/js/octokit.js b/assets/js/octokit.js index e3d97f2..703dddb 100644 --- a/assets/js/octokit.js +++ b/assets/js/octokit.js @@ -1,4 +1,28 @@ import { Octokit as RealOctokit } from '@octokit/rest'; import { throttling } from '@octokit/plugin-throttling'; -export const Octokit = RealOctokit.plugin(throttling); +export function Octokit(options) { + const ThrottledOctokit = RealOctokit.plugin(throttling); + + return new ThrottledOctokit({ + throttle: { + onRateLimit: (retryAfter, options) => { + console.warn( + `Request quota exhausted for request ${options.method} ${options.url}`, + ); + + console.info(`Retrying after ${retryAfter} seconds!`); + return true; + }, + onSecondaryRateLimit: (retryAfter, options) => { + console.warn( + `SecondaryRateLimit detected for request ${options.method} ${options.url}`, + ); + + console.info(`Retrying after ${retryAfter} seconds!`); + return true; + } + }, + ...options + }); +} diff --git a/content/credits/credits.js b/content/credits/credits.js index bb147f2..d36c958 100644 --- a/content/credits/credits.js +++ b/content/credits/credits.js @@ -241,12 +241,7 @@ function fixStats(contributorsStats) { } async function getContributors() { - const octokit = new Octokit({ - throttle: { - onSecondaryRateLimit: () => true, - onRateLimit: () => true - } - }); + const octokit = new Octokit(); const repos = await octokit.paginate(octokit.rest.repos.listForOrg, { org: 'loot' diff --git a/content/search/search.js b/content/search/search.js index ff11ef2..60ea22a 100644 --- a/content/search/search.js +++ b/content/search/search.js @@ -78,12 +78,7 @@ function onSearchInit(evt) { console.log("Loading masterlist..."); progress.classList.remove('hidden'); - const octokit = new Octokit({ - throttle: { - onSecondaryRateLimit: () => true, - onRateLimit: () => true - } - }); + const octokit = new Octokit(); octokit.rest.repos.getContent({ owner: 'loot',