Skip to content

Commit

Permalink
winget-source: retry also when status >= 400 (#103)
Browse files Browse the repository at this point in the history
  • Loading branch information
taoky authored Sep 28, 2023
1 parent 59cfc75 commit d220add
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions winget-source/utilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,18 @@ import { EX_IOERR, EX_SOFTWARE, EX_USAGE } from './sysexits.js'
/**
* `fetch` implementation with retry support.
*
* Defaults to 3 retries with 1000ms delay, on network errors only.
* 3 retries with 1000ms delay, on network errors and HTTP code >= 400.
*/
const fetch = withRetry(originalFetch);
const fetch = withRetry(originalFetch, {
retryOn: (attempt, error, response) => {
if (attempt > 3) return false;

if (error || response.status >= 400) {
winston.warn(`retrying ${response.url} (${attempt})`);
return true;
}
}
});

/** The remote URL of a pre-indexed WinGet source repository. */
const remote = process.env.WINGET_REPO_URL ?? 'https://cdn.winget.microsoft.com/cache';
Expand Down

0 comments on commit d220add

Please sign in to comment.