diff --git a/lib/api/gh-got-retry.js b/lib/api/gh-got-retry.js index a1922fcf60644c97274c414d6eca0d10e95b7ae9..ba2e6ce181231c996418ade9f0c6efd3dc0554e6 100644 --- a/lib/api/gh-got-retry.js +++ b/lib/api/gh-got-retry.js @@ -34,6 +34,19 @@ async function ghGotRetry(path, opts, retries = 5) { } return ghGotRetry(path, opts, retries - 1); } + if ( + retries > 0 && + err.statusCode === 403 && + err.message && + err.message.indexOf('API rate limit') === 0 + ) { + logger.debug(`Retrying API rate limit`); + // istanbul ignore if + if (process.env.NODE_ENV !== 'test') { + await sleep(30000 / (retries * retries)); + } + return ghGotRetry(path, opts, retries - 1); + } throw err; } } diff --git a/test/api/github.spec.js b/test/api/github.spec.js index 726e584d911fe1137aa8f8f304a3d35cfcf6f9e6..a3d59656dc2e3a8eb36224658966122e699bf071 100644 --- a/test/api/github.spec.js +++ b/test/api/github.spec.js @@ -75,6 +75,12 @@ describe('api/github', () => { statusCode: 502, }) ); + ghGot.mockImplementationOnce(() => + Promise.reject({ + statusCode: 403, + message: 'API rate limit exceeded for x.', + }) + ); ghGot.mockImplementationOnce(() => Promise.reject({ statusCode: 403,