Skip to content

Commit

Permalink
Polish code
Browse files Browse the repository at this point in the history
Signed-off-by: Xuanwo <[email protected]>
  • Loading branch information
Xuanwo committed May 14, 2024
1 parent e877ce2 commit 5b89ebe
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 18 deletions.
24 changes: 6 additions & 18 deletions core/src/raw/http_util/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,17 +106,11 @@ impl HttpClient {
}

let mut resp = req_builder.send().await.map_err(|err| {
let is_temporary = is_temporary_error(&err);

let mut oerr = Error::new(ErrorKind::Unexpected, "send http request")
Error::new(ErrorKind::Unexpected, "send http request")
.with_operation("http_util::Client::send")
.with_context("url", uri.to_string())
.set_source(err);
if is_temporary {
oerr = oerr.set_temporary();
}

oerr
.with_temporary(is_temporary_error(&err))
.set_source(err)
})?;

// Get content length from header so that we can check it.
Expand Down Expand Up @@ -150,17 +144,11 @@ impl HttpClient {
.try_collect()
.await
.map_err(|err| {
let is_temporary = is_temporary_error(&err);

let mut oerr = Error::new(ErrorKind::Unexpected, "read data from http response")
Error::new(ErrorKind::Unexpected, "read data from http response")
.with_operation("http_util::Client::send")
.with_context("url", uri.to_string())
.set_source(err);
if is_temporary {
oerr = oerr.set_temporary();
}

oerr
.with_temporary(is_temporary_error(&err))
.set_source(err)
})?;

let buffer = Buffer::from(bs);
Expand Down
10 changes: 10 additions & 0 deletions core/src/types/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,16 @@ impl Error {
self
}

/// Set temporary status for error by given temporary.
///
/// By set temporary, we indicate this error is retryable.
pub(crate) fn with_temporary(mut self, temporary: bool) -> Self {
if temporary {
self.status = ErrorStatus::Temporary;
}
self
}

/// Set persistent status for error.
///
/// By setting persistent, we indicate the retry should be stopped.
Expand Down

0 comments on commit 5b89ebe

Please sign in to comment.