From 1e51ea9423d6e201f1f4cf0bbd048838e066b7d7 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 96002c08..7f5efbf0 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. @@ -60,7 +60,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; @@ -89,7 +89,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 3b347250..2460e194 100644 --- a/axum/src/json.rs +++ b/axum/src/json.rs @@ -219,7 +219,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]