diff --git a/src/error.rs b/src/error.rs index 7eb50d7..9018b0b 100644 --- a/src/error.rs +++ b/src/error.rs @@ -9,6 +9,10 @@ impl Error { fn kind(&self) -> Option<&UploadError> { self.inner.downcast_ref() } + + pub(crate) fn root_cause(&self) -> &(dyn std::error::Error + 'static) { + self.inner.root_cause() + } } impl std::fmt::Debug for Error { @@ -185,20 +189,11 @@ impl ResponseError for Error { } fn error_response(&self) -> HttpResponse { - if let Some(kind) = self.kind() { - HttpResponse::build(self.status_code()) - .content_type("application/json") - .body( - serde_json::to_string(&serde_json::json!({ "msg": kind.to_string() })) - .unwrap_or_else(|_| r#"{"msg":"Request failed"}"#.to_string()), - ) - } else { - HttpResponse::build(self.status_code()) - .content_type("application/json") - .body( - serde_json::to_string(&serde_json::json!({ "msg": "Unknown error" })) - .unwrap_or_else(|_| r#"{"msg":"Request failed"}"#.to_string()), - ) - } + HttpResponse::build(self.status_code()) + .content_type("application/json") + .body( + serde_json::to_string(&serde_json::json!({ "msg": self.root_cause().to_string() })) + .unwrap_or_else(|_| r#"{"msg":"Request failed"}"#.to_string()), + ) } } diff --git a/src/queue/process.rs b/src/queue/process.rs index db040ec..8ab48f0 100644 --- a/src/queue/process.rs +++ b/src/queue/process.rs @@ -106,7 +106,7 @@ where tracing::warn!("Failed to ingest\n{}\n{}", format!("{e}"), format!("{e:?}")); UploadResult::Failure { - message: e.to_string(), + message: e.root_cause().to_string(), } } };