From c91acec2d40f8c4cbe0fdb4bb460b9ade1abb67a Mon Sep 17 00:00:00 2001 From: tu6ge Date: Fri, 12 Jul 2024 12:38:46 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=BD=93=E6=9C=8D=E5=8A=A1=E7=AB=AF?= =?UTF-8?q?=E8=BF=94=E5=9B=9E=E9=94=99=E8=AF=AF=E6=97=B6=EF=BC=8C=E7=9B=B4?= =?UTF-8?q?=E6=8E=A5=E6=8A=9B=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 而不是继续进行业务处理 --- src/bucket.rs | 48 ++++++++++++++++++++++++++++++++++++------------ src/client.rs | 22 ++++++++++++++++------ src/error.rs | 2 ++ src/object.rs | 2 +- 4 files changed, 55 insertions(+), 19 deletions(-) diff --git a/src/bucket.rs b/src/bucket.rs index 640804e..a569dc5 100644 --- a/src/bucket.rs +++ b/src/bucket.rs @@ -117,14 +117,20 @@ impl Bucket { let header_map = client.authorization(&method, resource)?; - let content = reqwest::Client::new() + let response = reqwest::Client::new() .get(url) .headers(header_map) .send() - .await? - .text() .await?; + let is_success = response.status().is_success(); + + let content = response.text().await?; + + if !is_success { + return Err(OssError::Service(content)); + } + //println!("{}", content); #[derive(Debug, Deserialize)] @@ -147,14 +153,20 @@ impl Bucket { let header_map = client.authorization(&method, resource)?; - let content = reqwest::Client::new() + let response = reqwest::Client::new() .get(url) .headers(header_map) .send() - .await? - .text() .await?; + let is_success = response.status().is_success(); + + let content = response.text().await?; + + if !is_success { + return Err(OssError::Service(content)); + } + //println!("{content}"); Self::parse_info_xml(content) } @@ -238,14 +250,20 @@ impl Bucket { let header_map = client.authorization(&method, resource)?; - let content = reqwest::Client::new() + let response = reqwest::Client::new() .get(url) .headers(header_map) .send() - .await? - .text() .await?; + let is_success = response.status().is_success(); + + let content = response.text().await?; + + if !is_success { + return Err(OssError::Service(content)); + } + //println!("{content}"); #[derive(Debug, Deserialize)] @@ -272,14 +290,20 @@ impl Bucket { let header_map = client.authorization(&method, resource)?; - let content = reqwest::Client::new() + let response = reqwest::Client::new() .get(url) .headers(header_map) .send() - .await? - .text() .await?; + let is_success = response.status().is_success(); + + let content = response.text().await?; + + if !is_success { + return Err(OssError::Service(content)); + } + //println!("{content}"); let list = Self::parse_xml_objects(&content)?; diff --git a/src/client.rs b/src/client.rs index ad39e07..d68ad0a 100644 --- a/src/client.rs +++ b/src/client.rs @@ -187,14 +187,20 @@ impl Client { let header_map = self.authorization(&method, resource)?; - let content = reqwest::Client::new() + let response = reqwest::Client::new() .get(url) .headers(header_map) .send() - .await? - .text() .await?; + let is_success = response.status().is_success(); + + let content = response.text().await?; + + if !is_success { + return Err(OssError::Service(content)); + } + //println!("{}", content); #[derive(Debug, Deserialize)] @@ -221,14 +227,18 @@ impl Client { let header_map = self.authorization(&method, resource)?; - let content = reqwest::Client::new() + let response = reqwest::Client::new() .get(url) .headers(header_map) .send() - .await? - .text() .await?; + let is_success = response.status().is_success(); + let content = response.text().await?; + if !is_success { + return Err(OssError::Service(content)); + } + // println!("{content}"); Self::parse_xml(content, endpoint) diff --git a/src/error.rs b/src/error.rs index c61ab62..06f2845 100644 --- a/src/error.rs +++ b/src/error.rs @@ -34,6 +34,8 @@ pub enum OssError { Delete(String), + Service(String), + NoFoundBucket, ParseXml(#[from] serde_xml_rs::Error), diff --git a/src/object.rs b/src/object.rs index 31bbb69..ee4d792 100644 --- a/src/object.rs +++ b/src/object.rs @@ -243,7 +243,7 @@ impl Object { Ok(()) } else { let body = response.text().await?; - Err(OssError::Upload(body)) + Err(OssError::Service(body)) } }