mirror of
https://git.asonix.dog/asonix/pict-rs
synced 2025-01-12 04:25:49 +00:00
Return Root Cause error from backgrounded endpoint
This commit is contained in:
parent
f9b8e817e6
commit
ee0ce5bc38
2 changed files with 11 additions and 16 deletions
25
src/error.rs
25
src/error.rs
|
@ -9,6 +9,10 @@ impl Error {
|
||||||
fn kind(&self) -> Option<&UploadError> {
|
fn kind(&self) -> Option<&UploadError> {
|
||||||
self.inner.downcast_ref()
|
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 {
|
impl std::fmt::Debug for Error {
|
||||||
|
@ -185,20 +189,11 @@ impl ResponseError for Error {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn error_response(&self) -> HttpResponse {
|
fn error_response(&self) -> HttpResponse {
|
||||||
if let Some(kind) = self.kind() {
|
HttpResponse::build(self.status_code())
|
||||||
HttpResponse::build(self.status_code())
|
.content_type("application/json")
|
||||||
.content_type("application/json")
|
.body(
|
||||||
.body(
|
serde_json::to_string(&serde_json::json!({ "msg": self.root_cause().to_string() }))
|
||||||
serde_json::to_string(&serde_json::json!({ "msg": kind.to_string() }))
|
.unwrap_or_else(|_| r#"{"msg":"Request failed"}"#.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()),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -106,7 +106,7 @@ where
|
||||||
tracing::warn!("Failed to ingest\n{}\n{}", format!("{e}"), format!("{e:?}"));
|
tracing::warn!("Failed to ingest\n{}\n{}", format!("{e}"), format!("{e:?}"));
|
||||||
|
|
||||||
UploadResult::Failure {
|
UploadResult::Failure {
|
||||||
message: e.to_string(),
|
message: e.root_cause().to_string(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue