@within-7/jetr 0.7.4 → 0.7.5
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/cli.js +20 -2
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -63,8 +63,26 @@ async function request(path, options = {}) {
|
|
|
63
63
|
Authorization: `Bearer ${getToken()}`,
|
|
64
64
|
...options.headers || {}
|
|
65
65
|
};
|
|
66
|
-
const
|
|
67
|
-
|
|
66
|
+
const MAX_RETRIES = 3;
|
|
67
|
+
for (let attempt = 1; attempt <= MAX_RETRIES; attempt++) {
|
|
68
|
+
try {
|
|
69
|
+
return await fetch(url, { ...options, headers });
|
|
70
|
+
} catch (e) {
|
|
71
|
+
const isLast = attempt === MAX_RETRIES;
|
|
72
|
+
const code = e.cause?.code || e.code || "";
|
|
73
|
+
const retryable = ["ECONNRESET", "ETIMEDOUT", "ECONNREFUSED", "EAI_AGAIN", "UND_ERR_CONNECT_TIMEOUT"].includes(code) || e.message === "fetch failed";
|
|
74
|
+
if (retryable && !isLast) {
|
|
75
|
+
const delay = attempt * 2e3;
|
|
76
|
+
await new Promise((r) => setTimeout(r, delay));
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
if (e.message === "fetch failed") {
|
|
80
|
+
throw new Error(`Network error: cannot reach ${config.apiUrl} (check internet connection)`);
|
|
81
|
+
}
|
|
82
|
+
throw new Error(`Network error: ${e.message}${code ? ` [${code}]` : ""}`);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
throw new Error("Unreachable");
|
|
68
86
|
}
|
|
69
87
|
async function json(path, options = {}) {
|
|
70
88
|
const res = await request(path, options);
|