@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.
Files changed (2) hide show
  1. package/dist/cli.js +20 -2
  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 res = await fetch(url, { ...options, headers });
67
- return res;
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);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@within-7/jetr",
3
- "version": "0.7.4",
3
+ "version": "0.7.5",
4
4
  "description": "CLI for Jetr static site hosting",
5
5
  "type": "module",
6
6
  "bin": {