From b452a577a732fb2d31c9177018f95feaf4a2dec4 Mon Sep 17 00:00:00 2001 From: asonix Date: Mon, 11 Dec 2023 13:05:29 -0600 Subject: [PATCH] Add object ID to not found error --- src/store.rs | 1 + src/store/object_store.rs | 30 +++++++++++++++--------------- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/src/store.rs b/src/store.rs index af411b4..636f86e 100644 --- a/src/store.rs +++ b/src/store.rs @@ -76,6 +76,7 @@ impl From for StoreError { e @ crate::store::object_store::ObjectError::Status( actix_web::http::StatusCode::NOT_FOUND, _, + _, ) => Self::ObjectNotFound(e), e => Self::ObjectStore(e), } diff --git a/src/store/object_store.rs b/src/store/object_store.rs index 71a34ce..dd22e27 100644 --- a/src/store/object_store.rs +++ b/src/store/object_store.rs @@ -68,8 +68,8 @@ pub(crate) enum ObjectError { #[error("Task cancelled")] Canceled, - #[error("Invalid status: {0}\n{1}")] - Status(StatusCode, String), + #[error("Invalid status {0} for {2:?} - {1}")] + Status(StatusCode, String, Option>), } #[derive(Debug)] @@ -105,7 +105,7 @@ impl ObjectError { | Self::Xml(_) | Self::Length | Self::Etag - | Self::Status(_, _) => ErrorCode::OBJECT_REQUEST_ERROR, + | Self::Status(_, _, _) => ErrorCode::OBJECT_REQUEST_ERROR, Self::IO(_) => ErrorCode::OBJECT_IO_ERROR, Self::Utf8(_) => ErrorCode::PARSE_OBJECT_ID_ERROR, Self::Canceled => ErrorCode::PANIC, @@ -187,7 +187,7 @@ where Ok(buf) } -async fn status_error(response: Response) -> StoreError { +async fn status_error(response: Response, object: Option>) -> StoreError { let status = response.status(); let body = match response.text().await { @@ -195,7 +195,7 @@ async fn status_error(response: Response) -> StoreError { Ok(body) => body, }; - ObjectError::Status(status, body).into() + ObjectError::Status(status, body, object).into() } #[async_trait::async_trait(?Send)] @@ -210,7 +210,7 @@ impl Store for ObjectStore { .map_err(ObjectError::from)?; if !response.status().is_success() { - return Err(status_error(response).await); + return Err(status_error(response, None).await); } Ok(()) @@ -252,7 +252,7 @@ impl Store for ObjectStore { .map_err(ObjectError::from)?; if !response.status().is_success() { - return Err(status_error(response).await); + return Err(status_error(response, None).await); } return Ok(object_id); @@ -268,7 +268,7 @@ impl Store for ObjectStore { .map_err(ObjectError::from)?; if !response.status().is_success() { - return Err(status_error(response).await); + return Err(status_error(response, None).await); } let body = response.text().await.map_err(ObjectError::Request)?; @@ -316,7 +316,7 @@ impl Store for ObjectStore { .map_err(ObjectError::from)?; if !response.status().is_success() { - return Err(status_error(response).await); + return Err(status_error(response, None).await); } let etag = response @@ -357,7 +357,7 @@ impl Store for ObjectStore { .map_err(ObjectError::from)?; if !response.status().is_success() { - return Err(status_error(response).await); + return Err(status_error(response, None).await); } Ok(()) as Result<(), StoreError> @@ -392,7 +392,7 @@ impl Store for ObjectStore { .map_err(ObjectError::from)?; if !response.status().is_success() { - return Err(status_error(response).await); + return Err(status_error(response, None).await); } Ok(object_id) @@ -420,7 +420,7 @@ impl Store for ObjectStore { .map_err(ObjectError::from)?; if !response.status().is_success() { - return Err(status_error(response).await); + return Err(status_error(response, Some(identifier.clone())).await); } Ok(Box::pin(crate::stream::metrics( @@ -448,7 +448,7 @@ impl Store for ObjectStore { if !response.status().is_success() { return Err(std::io::Error::new( std::io::ErrorKind::Other, - status_error(response).await, + status_error(response, Some(identifier.clone())).await, )); } @@ -477,7 +477,7 @@ impl Store for ObjectStore { .map_err(ObjectError::from)?; if !response.status().is_success() { - return Err(status_error(response).await); + return Err(status_error(response, Some(identifier.clone())).await); } let length = response @@ -502,7 +502,7 @@ impl Store for ObjectStore { .map_err(ObjectError::from)?; if !response.status().is_success() { - return Err(status_error(response).await); + return Err(status_error(response, Some(identifier.clone())).await); } Ok(())