Skip to content

Commit f5ff73c

Browse files
committed
Report errors with a HTTP code other than 200
Also, smush the error cause chain into a single string for the message.
1 parent 7b99a67 commit f5ff73c

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

ui/src/server_axum.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -727,10 +727,13 @@ impl<T> CacheInfo<T> {
727727

728728
impl IntoResponse for Error {
729729
fn into_response(self) -> axum::response::Response {
730-
Json(ErrorJson {
731-
error: self.to_string(),
732-
})
733-
.into_response()
730+
let error = snafu::CleanedErrorText::new(&self)
731+
.map(|(_, s, _)| s)
732+
.reduce(|l, r| l + ": " + &r)
733+
.unwrap_or_default();
734+
let resp = Json(ErrorJson { error });
735+
let resp = (StatusCode::INTERNAL_SERVER_ERROR, resp);
736+
resp.into_response()
734737
}
735738
}
736739

@@ -754,7 +757,9 @@ where
754757
Ok(v) => Ok(Self(v.0)),
755758
Err(e) => {
756759
let error = format!("Unable to deserialize request: {e}");
757-
Err(axum::Json(ErrorJson { error }).into_response())
760+
let resp = axum::Json(ErrorJson { error });
761+
let resp = (StatusCode::BAD_REQUEST, resp);
762+
Err(resp.into_response())
758763
}
759764
}
760765
}

0 commit comments

Comments
 (0)