diff --git a/axum-core/CHANGELOG.md b/axum-core/CHANGELOG.md index bb860389..755941b3 100644 --- a/axum-core/CHANGELOG.md +++ b/axum-core/CHANGELOG.md @@ -9,6 +9,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 # 0.5.0 +- **change:** The `Display` impl of all rejections generated by the + `define_rejection!()` will now include the `Display` output of the + inner error too. This matches the `body_text()` fn output now. ([#3118]) + +[#3118]: https://github.com/tokio-rs/axum/pull/3118 + ## rc.1 - **breaking:**: `Option` as an extractor now requires `T` to implement the diff --git a/axum-core/src/macros.rs b/axum-core/src/macros.rs index 1c035160..8f276248 100644 --- a/axum-core/src/macros.rs +++ b/axum-core/src/macros.rs @@ -50,7 +50,7 @@ macro_rules! __define_rejection { impl $name { /// Get the response body text used for this rejection. pub fn body_text(&self) -> String { - $body.into() + self.to_string() } /// Get the status code used for this rejection. @@ -107,7 +107,7 @@ macro_rules! __define_rejection { /// Get the response body text used for this rejection. pub fn body_text(&self) -> String { - format!(concat!($body, ": {}"), self.0).into() + self.to_string() } /// Get the status code used for this rejection. @@ -132,7 +132,9 @@ macro_rules! __define_rejection { impl std::fmt::Display for $name { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!(f, "{}", $body) + f.write_str($body)?; + f.write_str(": ")?; + self.0.fmt(f) } }