@within-7/jetr 0.7.3 → 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 +25 -3
- 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);
|
|
@@ -824,7 +842,11 @@ async function ensureSiteExists(spinner, siteName) {
|
|
|
824
842
|
spinner.text = "Checking site...";
|
|
825
843
|
try {
|
|
826
844
|
await api.getSite(siteName);
|
|
827
|
-
} catch {
|
|
845
|
+
} catch (e) {
|
|
846
|
+
const msg = e.message || "";
|
|
847
|
+
if (msg.includes("Forbidden")) {
|
|
848
|
+
throw new Error(`Site "${siteName}" belongs to another user`);
|
|
849
|
+
}
|
|
828
850
|
spinner.text = `Creating site ${siteName}...`;
|
|
829
851
|
await api.createSite(siteName);
|
|
830
852
|
}
|