From f5b40e8cfe33483bc75e8ff5dd9992fd4c6b3194 Mon Sep 17 00:00:00 2001 From: Jia Chao Date: Fri, 5 Jul 2024 14:59:01 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20async=5Fdownload=20=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E6=A3=80=E6=9F=A5=E8=BF=9E=E6=8E=A5=E7=8A=B6=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jia Chao --- src/file.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/file.rs b/src/file.rs index 5a16592..47c0851 100644 --- a/src/file.rs +++ b/src/file.rs @@ -146,6 +146,11 @@ pub async fn async_download>(url: String, target: Option

) -> c // 发送 GET 请求获取响应 let response = client.get(url.clone()).send().await?; + // 检查连接状态,失败会返回错误 + if !response.status().is_success() { + return Err(format!("下载 {} 失败:{}", url, response.status()).into()); + } + // 确定下载文件的路径 let download_file = match target { Some(file) => {