@supacloud/cli 0.14.1 → 0.14.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +29 -12
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -6335,29 +6335,46 @@ function resolveSupaCloudContext(env = process.env, cwd = process.cwd()) {
|
|
|
6335
6335
|
var DEFAULT_TIMEOUT = 30000;
|
|
6336
6336
|
var MAX_RETRIES = 2;
|
|
6337
6337
|
var RETRY_BASE_DELAY = 500;
|
|
6338
|
-
|
|
6338
|
+
function isRetryableMethod(method) {
|
|
6339
|
+
const normalizedMethod = (method ?? "GET").toUpperCase();
|
|
6340
|
+
return normalizedMethod === "GET" || normalizedMethod === "HEAD";
|
|
6341
|
+
}
|
|
6342
|
+
function isRetryableError(error) {
|
|
6343
|
+
if (!(error instanceof Error))
|
|
6344
|
+
return false;
|
|
6345
|
+
const networkError = error;
|
|
6346
|
+
return networkError.name === "AbortError" || networkError.code === "ECONNREFUSED" || networkError.code === "ECONNRESET";
|
|
6347
|
+
}
|
|
6348
|
+
async function fetchWithTimeout(url, options) {
|
|
6349
|
+
const controller = new AbortController;
|
|
6350
|
+
const timeout = setTimeout(() => controller.abort(), DEFAULT_TIMEOUT);
|
|
6351
|
+
try {
|
|
6352
|
+
return await fetch(url, {
|
|
6353
|
+
...options,
|
|
6354
|
+
signal: controller.signal
|
|
6355
|
+
});
|
|
6356
|
+
} finally {
|
|
6357
|
+
clearTimeout(timeout);
|
|
6358
|
+
}
|
|
6359
|
+
}
|
|
6360
|
+
async function fetchWithRetry(url, options) {
|
|
6361
|
+
const retries = isRetryableMethod(options.method) ? MAX_RETRIES : 0;
|
|
6339
6362
|
for (let attempt = 0;attempt <= retries; attempt++) {
|
|
6340
6363
|
try {
|
|
6341
|
-
const
|
|
6342
|
-
|
|
6343
|
-
const res = await fetch(url, {
|
|
6344
|
-
...options,
|
|
6345
|
-
signal: controller.signal
|
|
6346
|
-
});
|
|
6347
|
-
clearTimeout(timeout);
|
|
6348
|
-
if (res.status >= 500 && attempt < retries) {
|
|
6364
|
+
const res = await fetchWithTimeout(url, options);
|
|
6365
|
+
if (res.status >= 500 && res.status < 600 && attempt < retries) {
|
|
6349
6366
|
const delay = RETRY_BASE_DELAY * Math.pow(2, attempt);
|
|
6350
6367
|
await new Promise((r) => setTimeout(r, delay));
|
|
6351
6368
|
continue;
|
|
6352
6369
|
}
|
|
6353
6370
|
return res;
|
|
6354
|
-
} catch (
|
|
6355
|
-
if (attempt < retries && (
|
|
6371
|
+
} catch (error) {
|
|
6372
|
+
if (attempt < retries && isRetryableError(error)) {
|
|
6356
6373
|
const delay = RETRY_BASE_DELAY * Math.pow(2, attempt);
|
|
6357
6374
|
await new Promise((r) => setTimeout(r, delay));
|
|
6358
6375
|
continue;
|
|
6359
6376
|
}
|
|
6360
|
-
throw
|
|
6377
|
+
throw error;
|
|
6361
6378
|
}
|
|
6362
6379
|
}
|
|
6363
6380
|
throw new Error("Unreachable");
|