fix: async_download 增加检查连接状态
Signed-off-by: Jia Chao <jiac13@chinaunicom.cn>
This commit is contained in:
parent
0e0ce22bc0
commit
f5b40e8cfe
@ -146,6 +146,11 @@ pub async fn async_download<P: AsRef<Path>>(url: String, target: Option<P>) -> 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) => {
|
||||
|
Loading…
x
Reference in New Issue
Block a user