From bf306dfec388a4840ccd06e77aff839ab6c74b1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=B4=80=E1=B4=8D=E1=B4=9B=E1=B4=8F=E1=B4=80=E1=B4=87?= =?UTF-8?q?=CA=80?= Date: Wed, 19 Feb 2025 20:40:40 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20=E8=A1=A5=E4=B8=8A=E7=BC=BA=E5=A4=B1?= =?UTF-8?q?=E7=9A=84=20error=5Ffor=5Fstatus=20=E8=B0=83=E7=94=A8=EF=BC=8C?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=B8=80=E4=B8=AA=20clippy=20=E6=A0=BC?= =?UTF-8?q?=E5=BC=8F=E9=94=99=E8=AF=AF=20(#273)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/bili_sync/src/bilibili/credential.rs | 1 + crates/bili_sync/src/bilibili/video.rs | 2 ++ crates/bili_sync/src/downloader.rs | 7 ++++++- crates/bili_sync/src/utils/status.rs | 12 +++++------- 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/crates/bili_sync/src/bilibili/credential.rs b/crates/bili_sync/src/bilibili/credential.rs index 00e0c1f..48d1c4f 100644 --- a/crates/bili_sync/src/bilibili/credential.rs +++ b/crates/bili_sync/src/bilibili/credential.rs @@ -55,6 +55,7 @@ impl Credential { .request(Method::GET, "https://api.bilibili.com/x/web-interface/nav", Some(self)) .send() .await? + .error_for_status()? .json::() .await? .validate()?; diff --git a/crates/bili_sync/src/bilibili/video.rs b/crates/bili_sync/src/bilibili/video.rs index ca5bfe0..d4cb191 100644 --- a/crates/bili_sync/src/bilibili/video.rs +++ b/crates/bili_sync/src/bilibili/video.rs @@ -177,6 +177,7 @@ impl<'a> Video<'a> { )) .send() .await? + .error_for_status()? .json::() .await? .validate()?; @@ -198,6 +199,7 @@ impl<'a> Video<'a> { .request(Method::GET, format!("https:{}", &info.subtitle_url).as_str(), None) .send() .await? + .error_for_status()? .json::() .await?; let body: SubTitleBody = serde_json::from_value(res["body"].take())?; diff --git a/crates/bili_sync/src/downloader.rs b/crates/bili_sync/src/downloader.rs index e3bb747..cb55c1a 100644 --- a/crates/bili_sync/src/downloader.rs +++ b/crates/bili_sync/src/downloader.rs @@ -26,7 +26,12 @@ impl Downloader { fs::create_dir_all(parent).await?; } let mut file = File::create(path).await?; - let resp = self.client.request(Method::GET, url, None).send().await?; + let resp = self + .client + .request(Method::GET, url, None) + .send() + .await? + .error_for_status()?; let expected = resp.content_length().unwrap_or_default(); let mut stream_reader = StreamReader::new(resp.bytes_stream().map_err(std::io::Error::other)); let received = tokio::io::copy(&mut stream_reader, &mut file).await?; diff --git a/crates/bili_sync/src/utils/status.rs b/crates/bili_sync/src/utils/status.rs index 0e82613..44e15d2 100644 --- a/crates/bili_sync/src/utils/status.rs +++ b/crates/bili_sync/src/utils/status.rs @@ -114,13 +114,11 @@ impl Status { if let ExecutionStatus::FixedFailed(status, _) = result { assert!(*status < 0b1000, "status should be less than 0b1000"); self.set_status(offset, *status); - } else { - if self.get_status(offset) < STATUS_MAX_RETRY { - match result { - ExecutionStatus::Succeeded | ExecutionStatus::Skipped => self.set_ok(offset), - ExecutionStatus::Failed(_) => self.plus_one(offset), - _ => {} - } + } else if self.get_status(offset) < STATUS_MAX_RETRY { + match result { + ExecutionStatus::Succeeded | ExecutionStatus::Skipped => self.set_ok(offset), + ExecutionStatus::Failed(_) => self.plus_one(offset), + _ => {} } } }