MCPcopy Create free account
hub / github.com/EvanBacon/App-Store-Connect-OpenAPI-Spec / downloadWithRetry

Function downloadWithRetry

update/getLatestSpecAsync.ts:28–55  ·  view source on GitHub ↗
(url: string, dest: string)

Source from the content-addressed store, hash-verified

26}
27
28async function downloadWithRetry(url: string, dest: string): Promise<void> {
29 for (let attempt = 1; attempt <= MAX_RETRIES; attempt++) {
30 try {
31 const response = await fetch(url);
32 if (!response.ok) {
33 throw new Error(`HTTP ${response.status}: ${response.statusText}`);
34 }
35 await Bun.write(dest, response);
36 return;
37 } catch (error) {
38 const isLastAttempt = attempt === MAX_RETRIES;
39 console.error(
40 `Download attempt ${attempt}/${MAX_RETRIES} failed:`,
41 error instanceof Error ? error.message : error
42 );
43 if (isLastAttempt) {
44 throw new Error(
45 `Failed to download spec after ${MAX_RETRIES} attempts: ${
46 error instanceof Error ? error.message : error
47 }`
48 );
49 }
50 const backoff = INITIAL_BACKOFF_MS * Math.pow(2, attempt - 1);
51 console.log(`Retrying in ${backoff}ms...`);
52 await Bun.sleep(backoff);
53 }
54 }
55}
56
57async function unzipToDirectoryAsync(
58 zipFile: string,

Callers 1

getLatestSpecAsyncFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected