@forge/cli-shared

9.3.1-next.19.3.1-next.1-experimental-0b00ed8
out/shared/error-handling.js
~out/shared/error-handling.jsModified
+30−4
Index: package/out/shared/error-handling.js
===================================================================
--- package/out/shared/error-handling.js
+++ package/out/shared/error-handling.js
@@ -10,16 +10,42 @@
 const assistant_cli_1 = require("./assistant-cli");
 function isErrorWithAnalytics(e) {
     return e.getAttributes !== undefined;
 }
+const NETWORK_CONNECTIVITY_ERROR_CODES = new Set([
+    'ENOTFOUND',
+    'ECONNRESET',
+    'ECONNREFUSED',
+    'ECONNABORTED',
+    'ENETUNREACH',
+    'EHOSTUNREACH',
+    'EAI_AGAIN',
+    'ETIMEDOUT',
+    'UND_ERR_CONNECT_TIMEOUT',
+    'UND_ERR_HEADERS_TIMEOUT',
+    'UND_ERR_SOCKET'
+]);
+function isLikelyNetworkError(e) {
+    if (!(e instanceof Error)) {
+        return false;
+    }
+    if (e instanceof TypeError && e.message === 'fetch failed') {
+        const causeCode = e.cause && typeof e.cause === 'object' && typeof e.cause.code === 'string'
+            ? e.cause.code
+            : undefined;
+        return causeCode ? NETWORK_CONNECTIVITY_ERROR_CODES.has(causeCode) : false;
+    }
+    if (e.constructor?.name === 'FetchError' && e.type === 'system') {
+        return true;
+    }
+    return false;
+}
 function isUserError(e) {
     if (isErrorWithAnalytics(e)) {
         return e.getAttributes().isUserError ?? false;
     }
-    if (e.constructor?.name === 'FetchError') {
-        if (e.type === 'system') {
-            return true;
-        }
+    if (isLikelyNetworkError(e)) {
+        return true;
     }
     return false;
 }
 function getErrorAttributes(e) {