From 1327844736dc7f39075c0cad0060a8fb3129fcc9 Mon Sep 17 00:00:00 2001 From: idranme <96647698+idranme@users.noreply.github.com> Date: Wed, 10 Jul 2024 03:25:25 +0000 Subject: [PATCH 1/2] fix: error catch --- src/common/utils/file.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/common/utils/file.ts b/src/common/utils/file.ts index d5ccf4a1..564cccc9 100644 --- a/src/common/utils/file.ts +++ b/src/common/utils/file.ts @@ -160,7 +160,12 @@ export async function httpDownload(options: string | HttpDownloadOptions): Promi } } } - const fetchRes = await fetch(url, { headers }); + const fetchRes = await fetch(url, { headers }).catch((err) => { + if(err.cause){ + throw err.cause + } + throw err + }); if (!fetchRes.ok) throw new Error(`下载文件失败: ${fetchRes.statusText}`); const blob = await fetchRes.blob(); From 115120d066fd17d141b17e5665397af3de32c9a9 Mon Sep 17 00:00:00 2001 From: idranme <96647698+idranme@users.noreply.github.com> Date: Wed, 10 Jul 2024 11:35:55 +0800 Subject: [PATCH 2/2] Update file.ts --- src/common/utils/file.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/common/utils/file.ts b/src/common/utils/file.ts index 564cccc9..c6d6bcff 100644 --- a/src/common/utils/file.ts +++ b/src/common/utils/file.ts @@ -161,10 +161,10 @@ export async function httpDownload(options: string | HttpDownloadOptions): Promi } } const fetchRes = await fetch(url, { headers }).catch((err) => { - if(err.cause){ - throw err.cause + if (err.cause) { + throw err.cause; } - throw err + throw err; }); if (!fetchRes.ok) throw new Error(`下载文件失败: ${fetchRes.statusText}`);