Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3335964
D13645.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
4 KB
Referenced Files
None
Subscribers
None
D13645.diff
View Options
diff --git a/shared/comm-lib/src/blob/client.rs b/shared/comm-lib/src/blob/client.rs
--- a/shared/comm-lib/src/blob/client.rs
+++ b/shared/comm-lib/src/blob/client.rs
@@ -158,23 +158,18 @@
.await
.map_err(BlobServiceError::ClientError)?;
- debug!("Response status: {}", response.status());
- if response.status().is_success() {
- let stream = response.bytes_stream().map(|result| match result {
- Ok(bytes) => Ok(bytes),
- Err(error) => {
- warn!("Error while streaming response: {}", error);
- Err(BlobServiceError::ClientError(error))
- }
- });
- return Ok(stream);
+ if !response.status().is_success() {
+ return error_response_result(response).await;
}
- let error = handle_http_error(response.status());
- if let Ok(message) = response.text().await {
- trace!("Error response message: {}", message);
- }
- Err(error)
+ let stream = response.bytes_stream().map(|result| match result {
+ Ok(bytes) => Ok(bytes),
+ Err(error) => {
+ warn!("Error while streaming response: {}", error);
+ Err(BlobServiceError::ClientError(error))
+ }
+ });
+ Ok(stream)
}
/// Assigns a new holder to a blob represented by [`blob_hash`].
@@ -199,18 +194,13 @@
.send()
.await?;
- debug!("Response status: {}", response.status());
- if response.status().is_success() {
- let AssignHolderResponse { data_exists } = response.json().await?;
- trace!("Data exists: {}", data_exists);
- return Ok(data_exists);
+ if !response.status().is_success() {
+ return error_response_result(response).await;
}
- let error = handle_http_error(response.status());
- if let Ok(message) = response.text().await {
- trace!("Error response message: {}", message);
- }
- Err(error)
+ let AssignHolderResponse { data_exists } = response.json().await?;
+ trace!("Data exists: {}", data_exists);
+ Ok(data_exists)
}
/// Revokes given holder from a blob represented by [`blob_hash`].
@@ -236,18 +226,13 @@
.json(&payload)
.send()
.await?;
- debug!("Response status: {}", response.status());
if response.status().is_success() {
trace!("Revoke holder request successful");
return Ok(());
}
- let error = handle_http_error(response.status());
- if let Ok(message) = response.text().await {
- trace!("Error response message: {}", message);
- }
- Err(error)
+ error_response_result(response).await
}
/// Removes multiple holders.
@@ -278,22 +263,17 @@
.json(&payload)
.send()
.await?;
- debug!("Response status: {}", response.status());
- if response.status().is_success() {
- let result: RemoveHoldersResponse = response.json().await?;
- debug!(
- "Request successful. {} holders failed to be removed.",
- result.failed_requests.len()
- );
- return Ok(result);
+ if !response.status().is_success() {
+ return error_response_result(response).await;
}
- let error = handle_http_error(response.status());
- if let Ok(message) = response.text().await {
- debug!("Error response message: {}", message);
- }
- Err(error)
+ let result: RemoveHoldersResponse = response.json().await?;
+ debug!(
+ "Request successful. {} holders failed to be removed.",
+ result.failed_requests.len()
+ );
+ Ok(result)
}
/// Uploads a blob. Returns `BlobServiceError::AlreadyExists` if blob with given hash
@@ -337,7 +317,6 @@
.multipart(form)
.send()
.await?;
- debug!("Response status: {}", response.status());
if response.status().is_success() {
trace!("Blob upload successful");
@@ -457,6 +436,18 @@
}
}
+async fn error_response_result<T>(
+ response: reqwest::Response,
+) -> BlobResult<T> {
+ let status = response.status();
+ debug!("Response status: {}", status);
+ let error = handle_http_error(status);
+ if let Ok(message) = response.text().await {
+ trace!("Error response message: {}", message);
+ }
+ Err(error)
+}
+
type BlobResult<T> = Result<T, BlobServiceError>;
#[cfg(feature = "http")]
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Nov 22, 1:02 PM (17 h, 20 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2561419
Default Alt Text
D13645.diff (4 KB)
Attached To
Mode
D13645: [comm-lib][blob-client] Extract error handling logic
Attached
Detach File
Event Timeline
Log In to Comment