瀏覽代碼

fix: fetchAdvanced timeout abort on error

Sv443 9 月之前
父節點
當前提交
4cb3ce724e
共有 1 個文件被更改,包括 12 次插入7 次删除
  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 };
   }
 
-  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;
+  }
 }
 
 /**