diff --git a/axum-extra/CHANGELOG.md b/axum-extra/CHANGELOG.md index bda0ffaf84..7ed4c7fc60 100644 --- a/axum-extra/CHANGELOG.md +++ b/axum-extra/CHANGELOG.md @@ -7,7 +7,7 @@ and this project adheres to [Semantic Versioning]. # Unreleased -- None. +- **added:** Log rejections from built-in extractors with the `axum::rejection=trace` target ([#2596]) # 0.9.2 (13. January, 2024) diff --git a/axum-extra/src/extract/form.rs b/axum-extra/src/extract/form.rs index 1db0dd4392..48141af5b3 100644 --- a/axum-extra/src/extract/form.rs +++ b/axum-extra/src/extract/form.rs @@ -81,11 +81,16 @@ impl IntoResponse for FormRejection { fn into_response(self) -> Response { match self { Self::RawFormRejection(inner) => inner.into_response(), - Self::FailedToDeserializeForm(inner) => ( - StatusCode::BAD_REQUEST, - format!("Failed to deserialize form: {inner}"), - ) - .into_response(), + Self::FailedToDeserializeForm(inner) => { + let body = format!("Failed to deserialize form: {inner}"); + let status = StatusCode::BAD_REQUEST; + axum_core::__log_rejection!( + rejection_type = Self, + body_text = body, + status = status, + ); + (status, body).into_response() + } } } } diff --git a/axum-extra/src/extract/multipart.rs b/axum-extra/src/extract/multipart.rs index e865f74735..38377d06d6 100644 --- a/axum-extra/src/extract/multipart.rs +++ b/axum-extra/src/extract/multipart.rs @@ -379,7 +379,13 @@ pub struct InvalidBoundary; impl IntoResponse for InvalidBoundary { fn into_response(self) -> Response { - (self.status(), self.body_text()).into_response() + let body = self.body_text(); + axum_core::__log_rejection!( + rejection_type = Self, + body_text = body, + status = self.status(), + ); + (self.status(), body).into_response() } } diff --git a/axum-extra/src/extract/query.rs b/axum-extra/src/extract/query.rs index 3dda1a18d3..0479df1883 100644 --- a/axum-extra/src/extract/query.rs +++ b/axum-extra/src/extract/query.rs @@ -114,11 +114,16 @@ pub enum QueryRejection { impl IntoResponse for QueryRejection { fn into_response(self) -> Response { match self { - Self::FailedToDeserializeQueryString(inner) => ( - StatusCode::BAD_REQUEST, - format!("Failed to deserialize query string: {inner}"), - ) - .into_response(), + Self::FailedToDeserializeQueryString(inner) => { + let body = format!("Failed to deserialize query string: {inner}"); + let status = StatusCode::BAD_REQUEST; + axum_core::__log_rejection!( + rejection_type = Self, + body_text = body, + status = status, + ); + (status, body).into_response() + } } } } diff --git a/axum/src/extract/multipart.rs b/axum/src/extract/multipart.rs index 6a72335e74..0e9ef05621 100644 --- a/axum/src/extract/multipart.rs +++ b/axum/src/extract/multipart.rs @@ -274,12 +274,13 @@ impl std::error::Error for MultipartError { impl IntoResponse for MultipartError { fn into_response(self) -> Response { + let body = self.body_text(); axum_core::__log_rejection!( rejection_type = Self, - body_text = self.body_text(), + body_text = body, status = self.status(), ); - (self.status(), self.body_text()).into_response() + (self.status(), body).into_response() } } diff --git a/axum/src/extract/path/mod.rs b/axum/src/extract/path/mod.rs index 525946884f..b33acf56d3 100644 --- a/axum/src/extract/path/mod.rs +++ b/axum/src/extract/path/mod.rs @@ -398,12 +398,13 @@ impl FailedToDeserializePathParams { impl IntoResponse for FailedToDeserializePathParams { fn into_response(self) -> Response { + let body = self.body_text(); axum_core::__log_rejection!( rejection_type = Self, - body_text = self.body_text(), + body_text = body, status = self.status(), ); - (self.status(), self.body_text()).into_response() + (self.status(), body).into_response() } } @@ -530,7 +531,13 @@ impl std::error::Error for InvalidUtf8InPathParam {} impl IntoResponse for InvalidUtf8InPathParam { fn into_response(self) -> Response { - (self.status(), self.body_text()).into_response() + let body = self.body_text(); + axum_core::__log_rejection!( + rejection_type = Self, + body_text = body, + status = self.status(), + ); + (self.status(), body).into_response() } }