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)) } }