tustvold commented on code in PR #4915:
URL: https://github.com/apache/arrow-rs/pull/4915#discussion_r1352588238
##########
object_store/src/client/retry.rs:
##########
@@ -23,46 +23,50 @@ use futures::FutureExt;
use reqwest::header::LOCATION;
use reqwest::{Response, StatusCode};
use snafu::Error as SnafuError;
+use snafu::Snafu;
use std::time::{Duration, Instant};
use tracing::info;
/// Retry request error
-#[derive(Debug)]
-pub struct Error {
- retries: usize,
- message: String,
- source: Option<reqwest::Error>,
- status: Option<StatusCode>,
-}
-
-impl std::fmt::Display for Error {
- fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
- write!(
- f,
- "response error \"{}\", after {} retries",
- self.message, self.retries
- )?;
- if let Some(source) = &self.source {
- write!(f, ": {source}")?;
- }
- Ok(())
- }
-}
-
-impl std::error::Error for Error {
- fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
- self.source.as_ref().map(|e| e as _)
- }
+#[derive(Debug, Snafu)]
+pub enum Error {
+ #[snafu(display("Received redirect without LOCATION, this normally
indicates an incorrectly configured region"))]
+ BareRedirect,
+
+ #[snafu(display("Client error with status {status}: {}",
body.as_deref().unwrap_or("No Body")))]
+ Client {
+ status: StatusCode,
+ body: Option<String>,
+ },
+
+ #[snafu(display("Response error after {retries} retries: {source}"))]
+ Response {
+ retries: usize,
+ source: reqwest::Error,
+ },
}
impl Error {
/// Returns the status code associated with this error if any
pub fn status(&self) -> Option<StatusCode> {
- self.status
+ match self {
+ Error::BareRedirect => None,
+ Error::Client { status, .. } => Some(*status),
+ Error::Response { source, .. } => source.status(),
+ }
+ }
+
+ /// Returns the error body if any
+ pub fn body(&self) -> Option<&str> {
Review Comment:
Being able to provide this method is what originally motivated this PR
--
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]