File tree Expand file tree Collapse file tree 2 files changed +17
-7
lines changed
Expand file tree Collapse file tree 2 files changed +17
-7
lines changed Original file line number Diff line number Diff line change @@ -39,12 +39,6 @@ use crate::error::ServerError;
3939
4040type BoxFuture < T > = Pin < Box < dyn Future < Output = T > + Send > > ;
4141
42- impl IntoResponse for ServerError {
43- fn into_response ( self ) -> Response {
44- ( axum:: http:: StatusCode :: BAD_REQUEST , self . to_string ( ) ) . into_response ( )
45- }
46- }
47-
4842#[ derive( Clone ) ]
4943pub struct Field {
5044 name : String ,
Original file line number Diff line number Diff line change 11use aiscript_vm:: VmError ;
2- use axum:: extract:: rejection;
2+ use axum:: {
3+ Json ,
4+ extract:: rejection,
5+ response:: { IntoResponse , Response } ,
6+ } ;
37use thiserror:: Error ;
48
59#[ derive( Error , Debug ) ]
@@ -29,3 +33,15 @@ pub enum ServerError {
2933 // #[error("Internal server error: {0}")]
3034 // InternalError(String),
3135}
36+
37+ impl IntoResponse for ServerError {
38+ fn into_response ( self ) -> Response {
39+ // Convert the error to a JSON object with an "error" field
40+ let error_json = serde_json:: json!( {
41+ "error" : self . to_string( )
42+ } ) ;
43+
44+ // Return as a JSON response with BAD_REQUEST status
45+ ( axum:: http:: StatusCode :: BAD_REQUEST , Json ( error_json) ) . into_response ( )
46+ }
47+ }
You can’t perform that action at this time.
0 commit comments