Fix rejection status codes (#751)

This commit is contained in:
David Pedersen 2022-02-09 11:19:31 +01:00 committed by GitHub
parent 16ee83a799
commit 1e51ea9423
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 5 deletions

View File

@ -11,7 +11,7 @@ pub use axum_core::extract::rejection::*;
#[cfg(feature = "json")] #[cfg(feature = "json")]
define_rejection! { define_rejection! {
#[status = BAD_REQUEST] #[status = UNPROCESSABLE_ENTITY]
#[body = "Failed to parse the request body as JSON"] #[body = "Failed to parse the request body as JSON"]
#[cfg_attr(docsrs, doc(cfg(feature = "json")))] #[cfg_attr(docsrs, doc(cfg(feature = "json")))]
/// Rejection type for [`Json`](super::Json). /// Rejection type for [`Json`](super::Json).
@ -19,7 +19,7 @@ define_rejection! {
} }
define_rejection! { define_rejection! {
#[status = BAD_REQUEST] #[status = UNSUPPORTED_MEDIA_TYPE]
#[body = "Expected request with `Content-Type: application/json`"] #[body = "Expected request with `Content-Type: application/json`"]
/// Rejection type for [`Json`](super::Json) used if the `Content-Type` /// Rejection type for [`Json`](super::Json) used if the `Content-Type`
/// header is missing. /// header is missing.
@ -60,7 +60,7 @@ define_rejection! {
} }
define_rejection! { define_rejection! {
#[status = BAD_REQUEST] #[status = UNSUPPORTED_MEDIA_TYPE]
#[body = "Form requests must have `Content-Type: x-www-form-urlencoded`"] #[body = "Form requests must have `Content-Type: x-www-form-urlencoded`"]
/// Rejection type used if you try and extract the request more than once. /// Rejection type used if you try and extract the request more than once.
pub struct InvalidFormContentType; pub struct InvalidFormContentType;
@ -89,7 +89,7 @@ impl FailedToDeserializeQueryString {
impl IntoResponse for FailedToDeserializeQueryString { impl IntoResponse for FailedToDeserializeQueryString {
fn into_response(self) -> Response { fn into_response(self) -> Response {
let mut res = Response::new(boxed(Full::from(self.to_string()))); 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 res
} }
} }

View File

@ -219,7 +219,7 @@ mod tests {
let status = res.status(); let status = res.status();
dbg!(res.text().await); dbg!(res.text().await);
assert_eq!(status, StatusCode::BAD_REQUEST); assert_eq!(status, StatusCode::UNSUPPORTED_MEDIA_TYPE);
} }
#[tokio::test] #[tokio::test]