mirror of
https://github.com/tokio-rs/axum.git
synced 2025-10-01 15:00:46 +00:00
Fix rejection status codes (#751)
This commit is contained in:
parent
16ee83a799
commit
1e51ea9423
@ -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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user