Browse Source

fix: fetchAdvanced timeout abort on error

Sv443 9 months ago
parent
commit
4cb3ce724e
1 changed files with 12 additions and 7 deletions
  1. 12 7
      lib/misc.ts

+ 12 - 7
lib/misc.ts

@@ -73,13 +73,18 @@ export async function fetchAdvanced(input: RequestInfo | URL, options: FetchAdva
     signalOpts = { signal: controller.signal };
     signalOpts = { signal: controller.signal };
   }
   }
 
 
-  const res = await fetch(input, {
-    ...options,
-    ...signalOpts,
-  });
-
-  clearTimeout(id);
-  return res;
+  try {
+    const res = await fetch(input, {
+      ...options,
+      ...signalOpts,
+    });
+    id && clearTimeout(id);
+    return res;
+  }
+  catch(err) {
+    id && clearTimeout(id);
+    throw err;
+  }
 }
 }
 
 
 /**
 /**