Skip to content

Commit

Permalink
feat: 当服务端返回错误时,直接抛出
Browse files Browse the repository at this point in the history
而不是继续进行业务处理
  • Loading branch information
tu6ge committed Jul 12, 2024
1 parent d203ae8 commit c91acec
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 19 deletions.
48 changes: 36 additions & 12 deletions src/bucket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand All @@ -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)
}
Expand Down Expand Up @@ -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)]
Expand All @@ -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)?;
Expand Down
22 changes: 16 additions & 6 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand All @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ pub enum OssError {

Delete(String),

Service(String),

NoFoundBucket,

ParseXml(#[from] serde_xml_rs::Error),
Expand Down
2 changes: 1 addition & 1 deletion src/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ impl Object {
Ok(())
} else {
let body = response.text().await?;
Err(OssError::Upload(body))
Err(OssError::Service(body))
}
}

Expand Down

0 comments on commit c91acec

Please sign in to comment.