@@ -16,6 +16,7 @@ use crate::{
1616 api:: ApiError , internal:: InternalError ,
1717 invalid_req:: InvalidRequestError ,
1818 } ,
19+ types:: json:: Json ,
1920} ;
2021
2122#[ derive( Debug , Clone ) ]
7980#[ derive( Serialize ) ]
8081pub struct ValidateRouterConfigResponse {
8182 pub valid : bool ,
83+ pub error : Option < String > ,
8284}
8385
8486impl < S , ReqBody > Service < Request < ReqBody > > for ValidateRouterConfig < S , ReqBody >
@@ -125,22 +127,20 @@ where
125127 }
126128 } ;
127129
128- let valid = config. validate ( ) . is_ok ( ) ;
129- let response_body =
130- serde_json:: to_vec ( & ValidateRouterConfigResponse { valid } )
131- . expect (
132- "can always serialize a \
133- ValidateRouterConfigResponse",
134- ) ;
135-
136- Ok ( http:: Response :: builder ( )
137- . status ( http:: StatusCode :: OK )
138- . header ( http:: header:: CONTENT_TYPE , "application/json" )
139- . body ( axum_core:: body:: Body :: from ( response_body) )
140- . expect (
141- "serialized ValidateRouterConfigResponse is always a \
142- valid axum body",
143- ) )
130+ let validate_result = config. validate ( ) ;
131+ if let Err ( e) = validate_result {
132+ let body = Json ( ValidateRouterConfigResponse {
133+ valid : false ,
134+ error : Some ( e. to_string ( ) ) ,
135+ } ) ;
136+ return Ok ( body. into_response ( ) ) ;
137+ } else {
138+ let body = Json ( ValidateRouterConfigResponse {
139+ valid : true ,
140+ error : None ,
141+ } ) ;
142+ return Ok ( body. into_response ( ) ) ;
143+ }
144144 } ;
145145 Either :: Left ( Box :: pin ( fut) )
146146 } else {
0 commit comments