From 254ca6d214df6f3b2a063879360c929d5eac16b2 Mon Sep 17 00:00:00 2001 From: Tobias Bieniek Date: Thu, 26 Dec 2024 23:17:00 +0100 Subject: [PATCH] axum-core/macros: Avoid double `body_text()` calls in rejection macros --- axum-core/src/macros.rs | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/axum-core/src/macros.rs b/axum-core/src/macros.rs index aa99ba402e..97ae5a9d84 100644 --- a/axum-core/src/macros.rs +++ b/axum-core/src/macros.rs @@ -49,12 +49,15 @@ macro_rules! __define_rejection { impl $crate::response::IntoResponse for $name { fn into_response(self) -> $crate::response::Response { + let status = self.status(); + let body_text = self.body_text(); + $crate::__log_rejection!( rejection_type = $name, - body_text = $body, - status = http::StatusCode::$status, + body_text = body_text, + status = status, ); - (self.status(), $body).into_response() + (status, body_text).into_response() } } @@ -106,12 +109,15 @@ macro_rules! __define_rejection { impl $crate::response::IntoResponse for $name { fn into_response(self) -> $crate::response::Response { + let status = self.status(); + let body_text = self.body_text(); + $crate::__log_rejection!( rejection_type = $name, - body_text = self.body_text(), - status = http::StatusCode::$status, + body_text = body_text, + status = status, ); - (self.status(), self.body_text()).into_response() + (status, body_text).into_response() } }