File tree Expand file tree Collapse file tree 2 files changed +22
-2
lines changed
Expand file tree Collapse file tree 2 files changed +22
-2
lines changed Original file line number Diff line number Diff line change @@ -77,13 +77,24 @@ pub enum FormRejection {
7777 FailedToDeserializeForm ( Error ) ,
7878}
7979
80+ impl FormRejection {
81+ /// Get the status code used for this rejection.
82+ pub fn status ( & self ) -> StatusCode {
83+ // Make sure to keep this in sync with `IntoResponse` impl.
84+ match self {
85+ Self :: RawFormRejection ( inner) => inner. status ( ) ,
86+ Self :: FailedToDeserializeForm ( _) => StatusCode :: BAD_REQUEST ,
87+ }
88+ }
89+ }
90+
8091impl IntoResponse for FormRejection {
8192 fn into_response ( self ) -> Response {
93+ let status = self . status ( ) ;
8294 match self {
8395 Self :: RawFormRejection ( inner) => inner. into_response ( ) ,
8496 Self :: FailedToDeserializeForm ( inner) => {
8597 let body = format ! ( "Failed to deserialize form: {inner}" ) ;
86- let status = StatusCode :: BAD_REQUEST ;
8798 axum_core:: __log_rejection!(
8899 rejection_type = Self ,
89100 body_text = body,
Original file line number Diff line number Diff line change @@ -111,12 +111,21 @@ pub enum QueryRejection {
111111 FailedToDeserializeQueryString ( Error ) ,
112112}
113113
114+ impl QueryRejection {
115+ /// Get the status code used for this rejection.
116+ pub fn status ( & self ) -> StatusCode {
117+ match self {
118+ Self :: FailedToDeserializeQueryString ( _) => StatusCode :: BAD_REQUEST ,
119+ }
120+ }
121+ }
122+
114123impl IntoResponse for QueryRejection {
115124 fn into_response ( self ) -> Response {
125+ let status = self . status ( ) ;
116126 match self {
117127 Self :: FailedToDeserializeQueryString ( inner) => {
118128 let body = format ! ( "Failed to deserialize query string: {inner}" ) ;
119- let status = StatusCode :: BAD_REQUEST ;
120129 axum_core:: __log_rejection!(
121130 rejection_type = Self ,
122131 body_text = body,
You can’t perform that action at this time.
0 commit comments