Add object ID to not found error

This commit is contained in:
asonix 2023-12-11 13:21:05 -06:00
parent 63fe3a047f
commit 9971d3caeb
2 changed files with 15 additions and 14 deletions

View File

@ -49,6 +49,7 @@ impl From<crate::store::object_store::ObjectError> for StoreError {
e @ crate::store::object_store::ObjectError::Status( e @ crate::store::object_store::ObjectError::Status(
actix_web::http::StatusCode::NOT_FOUND, actix_web::http::StatusCode::NOT_FOUND,
_, _,
_,
) => Self::ObjectNotFound(e), ) => Self::ObjectNotFound(e),
e => Self::ObjectStore(e), e => Self::ObjectStore(e),
} }

View File

@ -71,8 +71,8 @@ pub(crate) enum ObjectError {
#[error("Task cancelled")] #[error("Task cancelled")]
Cancelled, Cancelled,
#[error("Invalid status: {0}\n{1}")] #[error("Invalid status {0} for {2:?} - {1}")]
Status(StatusCode, String), Status(StatusCode, String, Option<String>),
} }
impl From<JoinError> for ObjectError { impl From<JoinError> for ObjectError {
@ -144,7 +144,7 @@ where
Ok(buf) Ok(buf)
} }
async fn status_error(response: Response) -> StoreError { async fn status_error(response: Response, obj: Option<String>) -> StoreError {
let status = response.status(); let status = response.status();
let body = match response.text().await { let body = match response.text().await {
@ -152,7 +152,7 @@ async fn status_error(response: Response) -> StoreError {
Ok(body) => body, Ok(body) => body,
}; };
ObjectError::Status(status, body).into() ObjectError::Status(status, body, obj).into()
} }
#[async_trait::async_trait(?Send)] #[async_trait::async_trait(?Send)]
@ -169,7 +169,7 @@ impl Store for ObjectStore {
.map_err(ObjectError::from)?; .map_err(ObjectError::from)?;
if !response.status().is_success() { if !response.status().is_success() {
return Err(status_error(response).await); return Err(status_error(response, None).await);
} }
Ok(()) Ok(())
@ -210,7 +210,7 @@ impl Store for ObjectStore {
.map_err(ObjectError::from)?; .map_err(ObjectError::from)?;
if !response.status().is_success() { if !response.status().is_success() {
return Err(status_error(response).await); return Err(status_error(response, None).await);
} }
return Ok(object_id); return Ok(object_id);
@ -222,7 +222,7 @@ impl Store for ObjectStore {
let response = req.send().await.map_err(ObjectError::from)?; let response = req.send().await.map_err(ObjectError::from)?;
if !response.status().is_success() { 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)?; let body = response.text().await.map_err(ObjectError::Request)?;
@ -266,7 +266,7 @@ impl Store for ObjectStore {
.map_err(ObjectError::from)?; .map_err(ObjectError::from)?;
if !response.status().is_success() { if !response.status().is_success() {
return Err(status_error(response).await); return Err(status_error(response, None).await);
} }
let etag = response let etag = response
@ -307,7 +307,7 @@ impl Store for ObjectStore {
.map_err(ObjectError::from)?; .map_err(ObjectError::from)?;
if !response.status().is_success() { if !response.status().is_success() {
return Err(status_error(response).await); return Err(status_error(response, None).await);
} }
Ok(()) as Result<(), StoreError> Ok(()) as Result<(), StoreError>
@ -336,7 +336,7 @@ impl Store for ObjectStore {
let response = req.body(bytes).send().await.map_err(ObjectError::from)?; let response = req.body(bytes).send().await.map_err(ObjectError::from)?;
if !response.status().is_success() { if !response.status().is_success() {
return Err(status_error(response).await); return Err(status_error(response, None).await);
} }
Ok(object_id) Ok(object_id)
@ -356,7 +356,7 @@ impl Store for ObjectStore {
.map_err(ObjectError::from)?; .map_err(ObjectError::from)?;
if !response.status().is_success() { if !response.status().is_success() {
return Err(status_error(response).await); return Err(status_error(response, Some(identifier.as_str().to_string())).await);
} }
Ok(Box::pin( Ok(Box::pin(
@ -382,7 +382,7 @@ impl Store for ObjectStore {
if !response.status().is_success() { if !response.status().is_success() {
return Err(std::io::Error::new( return Err(std::io::Error::new(
std::io::ErrorKind::Other, std::io::ErrorKind::Other,
status_error(response).await, status_error(response, Some(identifier.as_str().to_string())).await,
)); ));
} }
@ -406,7 +406,7 @@ impl Store for ObjectStore {
.map_err(ObjectError::from)?; .map_err(ObjectError::from)?;
if !response.status().is_success() { if !response.status().is_success() {
return Err(status_error(response).await); return Err(status_error(response, Some(identifier.as_str().to_string())).await);
} }
let length = response let length = response
@ -430,7 +430,7 @@ impl Store for ObjectStore {
.map_err(ObjectError::from)?; .map_err(ObjectError::from)?;
if !response.status().is_success() { if !response.status().is_success() {
return Err(status_error(response).await); return Err(status_error(response, Some(identifier.as_str().to_string())).await);
} }
Ok(()) Ok(())