tustvold commented on code in PR #2574:
URL: https://github.com/apache/arrow-rs/pull/2574#discussion_r954733952


##########
object_store/src/client/retry.rs:
##########
@@ -85,22 +130,153 @@ impl RetryExt for reqwest::RequestBuilder {
             loop {
                 let s = self.try_clone().expect("request body must be 
cloneable");
                 match s.send().await {
-                    Err(e)
-                        if retries < max_retries
-                            && now.elapsed() < retry_timeout
-                            && e.status()
-                                .map(|s| s.is_server_error())
-                                .unwrap_or(false) =>
+                    Ok(r) => match r.error_for_status_ref() {
+                        Ok(_) => return Ok(r),
+                        Err(e) => {
+                            let status = r.status();
+
+                            if retries == max_retries
+                                || now.elapsed() > retry_timeout
+                                || !status.is_server_error() {
+
+                                // Get the response message if returned a 
client error
+                                let message = match status.is_client_error() {
+                                    true => match r.text().await {
+                                        Ok(message) if !message.is_empty() => 
message,
+                                        Ok(_) => "No Body".to_string(),
+                                        Err(e) => format!("error getting 
response body: {}", e)
+                                    }
+                                    false => status.to_string(),
+                                };
+
+                                return Err(Error{
+                                    message,
+                                    retries,
+                                    source: e,
+                                })
+
+                            }
+
+                            let sleep = backoff.next();
+                            retries += 1;
+                            info!("Encountered server error, backing off for 
{} seconds, retry {} of {}", sleep.as_secs_f32(), retries, max_retries);
+                            tokio::time::sleep(sleep).await;
+                        }
+                    },
+                    Err(e) =>
                     {
-                        let sleep = backoff.next();
-                        retries += 1;
-                        info!("Encountered server error, backing off for {} 
seconds, retry {} of {}", sleep.as_secs_f32(), retries, max_retries);
-                        tokio::time::sleep(sleep).await;
+                        return Err(Error{
+                            retries,
+                            message: "request error".to_string(),
+                            source: e
+                        })
                     }
-                    r => return r,
                 }
             }
         }
         .boxed()
     }
 }
+
+#[cfg(test)]
+mod tests {
+    use crate::client::retry::RetryExt;
+    use crate::RetryConfig;
+    use reqwest::header::{AUTHORIZATION, IF_MATCH};
+    use reqwest::{Client, Method, StatusCode};
+    use std::time::Duration;
+
+    #[tokio::test]

Review Comment:
   Fixed PTAL



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to