Skip to content

Commit

Permalink
Workaround for ghuser-io#8
Browse files Browse the repository at this point in the history
  • Loading branch information
lourot committed Sep 20, 2018
1 parent a66b1fe commit ff3e116
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
7 changes: 6 additions & 1 deletion fetchRepos.js
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,12 @@ optional arguments:
const perPage = 100;
for (let page = 1;; ++page) {
const ghUrl = `${pullsUrl}?state=all&page=${page}&per_page=${perPage}`;
const ghDataJson = await github.fetchGHJson(ghUrl, spinner);
const ghDataJson = await github.fetchGHJson(ghUrl, spinner, [500]);
if (ghDataJson === 500) { // Workaround for #8
spinner.fail();
return;
}

for (const pr of ghDataJson) {
authors.add(pr.user.login);
}
Expand Down
18 changes: 12 additions & 6 deletions impl/fetchJson.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,18 @@
// Else if the HTTP status code is in acceptedErrorCodes, returns it.
// Else throws the HTTP status code.

const data = await fetch(url, {
retryOn: [500, 502, 504, 522, 525],
headers: ifModifiedSince && {
'If-Modified-Since': ifModifiedSince.toUTCString()
} || null
});
let data;
try {
data = await fetch(url, {
retryOn: [500, 502, 504, 522, 525],
headers: ifModifiedSince && {
'If-Modified-Since': ifModifiedSince.toUTCString()
} || null
});
} catch (e) { // we end up here after too many retries
data = e;
}

const statusIsOk = Math.floor(data.status / 100) === 2;
if (!statusIsOk && acceptedErrorCodes.indexOf(data.status) > -1) {
return data.status;
Expand Down
2 changes: 1 addition & 1 deletion impl/github.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
try {
return await fetchJson(authify(url), oraSpinner, acceptedErrorCodes, ifModifiedSince);
} catch (e) {
console.error(`Error while fetching ${url}`);
console.error(`\nError while fetching ${url}`);
console.error('API rate limit state:');
console.error(rateLimit);
throw e;
Expand Down

0 comments on commit ff3e116

Please sign in to comment.