From 9bffd9d0db15284bfedfddac461957273ff38dcd Mon Sep 17 00:00:00 2001 From: David Pedersen Date: Wed, 9 Feb 2022 11:19:31 +0100 Subject: [PATCH] Fix rejection status codes (#751) --- axum/src/extract/rejection.rs | 8 ++++---- axum/src/json.rs | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/axum/src/extract/rejection.rs b/axum/src/extract/rejection.rs index 2777a64f..13537249 100644 --- a/axum/src/extract/rejection.rs +++ b/axum/src/extract/rejection.rs @@ -11,7 +11,7 @@ pub use axum_core::extract::rejection::*; #[cfg(feature = "json")] define_rejection! { - #[status = BAD_REQUEST] + #[status = UNPROCESSABLE_ENTITY] #[body = "Failed to parse the request body as JSON"] #[cfg_attr(docsrs, doc(cfg(feature = "json")))] /// Rejection type for [`Json`](super::Json). @@ -19,7 +19,7 @@ define_rejection! { } define_rejection! { - #[status = BAD_REQUEST] + #[status = UNSUPPORTED_MEDIA_TYPE] #[body = "Expected request with `Content-Type: application/json`"] /// Rejection type for [`Json`](super::Json) used if the `Content-Type` /// header is missing. @@ -59,7 +59,7 @@ define_rejection! { } define_rejection! { - #[status = BAD_REQUEST] + #[status = UNSUPPORTED_MEDIA_TYPE] #[body = "Form requests must have `Content-Type: x-www-form-urlencoded`"] /// Rejection type used if you try and extract the request more than once. pub struct InvalidFormContentType; @@ -88,7 +88,7 @@ impl FailedToDeserializeQueryString { impl IntoResponse for FailedToDeserializeQueryString { fn into_response(self) -> Response { let mut res = Response::new(boxed(Full::from(self.to_string()))); - *res.status_mut() = http::StatusCode::BAD_REQUEST; + *res.status_mut() = http::StatusCode::UNPROCESSABLE_ENTITY; res } } diff --git a/axum/src/json.rs b/axum/src/json.rs index 103e2997..3ac76247 100644 --- a/axum/src/json.rs +++ b/axum/src/json.rs @@ -223,7 +223,7 @@ mod tests { let status = res.status(); dbg!(res.text().await); - assert_eq!(status, StatusCode::BAD_REQUEST); + assert_eq!(status, StatusCode::UNSUPPORTED_MEDIA_TYPE); } #[tokio::test]