Files
Ncurator/scripts/release/shared/http.mjs
T
hy 7b057c05f8 refactor: reorganize scripts and update paths for build and release processes
- Removed obsolete test script `test_crawl4ai_fit_markdown.py`.
- Deleted `verify-package-main-obfuscation.mjs` as it is no longer needed.
- Updated paths in `app-update-publish-config.test.ts` to reflect new script locations.
- Refactored `package-content-policy.test.ts` to use new paths for content policy scripts.
- Adjusted `package-main-obfuscation.test.ts` to point to the new obfuscation script locations.
- Modified `package-size-budget.test.ts` to use updated paths for size budget scripts.
- Changed `r2-update-metadata-contract.test.ts` to reference the new metadata script.
- Updated `release-fragment-contract.test.ts` to use the new fragment contract script.
- Refactored `release-storage-layout.test.ts` to point to the new storage layout script.
- Added `runtime-trace.test.ts` to test runtime tracing functionality.
- Updated `node-pty-native-release.test.ts` to reflect new paths for native release scripts.
2026-07-20 17:03:38 +08:00

24 lines
772 B
JavaScript

const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms))
export const fetchWithRetry = async (url, options = {}, retryOptions = {}) => {
const attempts = Number(retryOptions.attempts || 5)
const delayMs = Number(retryOptions.delayMs || 2_000)
let lastError
let lastResponse
for (let attempt = 1; attempt <= attempts; attempt += 1) {
try {
const response = await fetch(url, options)
lastResponse = response
if (response.ok || response.status < 500 || attempt === attempts) return response
} catch (error) {
lastError = error
if (attempt === attempts) throw error
}
await delay(delayMs * attempt)
}
if (lastResponse) return lastResponse
throw lastError || new Error(`request failed: ${url}`)
}