@@ -35,23 +35,16 @@ pub enum CheckHealthError {
3535
3636impl IntoResponse for CheckHealthError {
3737 fn into_response ( self ) -> AxumResponse {
38- let ( status, error_message) = match & self {
39- CheckHealthError :: DeploymentNotFound => ( StatusCode :: NOT_FOUND , "Deployment not found" ) ,
40- CheckHealthError :: BadResponse => (
41- StatusCode :: INTERNAL_SERVER_ERROR ,
42- "Failed to decode response" ,
43- ) ,
44- CheckHealthError :: RequestFailed => ( StatusCode :: BAD_GATEWAY , "Failed to send request" ) ,
45- CheckHealthError :: InvalidHealthStatus => (
46- StatusCode :: INTERNAL_SERVER_ERROR ,
47- "Invalid health status found" ,
48- ) ,
38+ let status = match & self {
39+ CheckHealthError :: DeploymentNotFound => StatusCode :: NOT_FOUND ,
40+ CheckHealthError :: InvalidHealthStatus | CheckHealthError :: BadResponse => {
41+ StatusCode :: INTERNAL_SERVER_ERROR
42+ }
43+ CheckHealthError :: RequestFailed => StatusCode :: BAD_GATEWAY ,
4944 } ;
50-
5145 let body = serde_json:: json!( {
52- "error" : error_message ,
46+ "error" : self . to_string ( ) ,
5347 } ) ;
54-
5548 ( status, Json ( body) ) . into_response ( )
5649 }
5750}
@@ -79,15 +72,12 @@ pub async fn health(
7972
8073 let data = match ( graphql_response. data , graphql_response. errors ) {
8174 ( Some ( data) , None ) => data,
82- ( _, Some ( _) ) => return Err ( CheckHealthError :: BadResponse ) ,
83- ( _, _) => return Err ( CheckHealthError :: BadResponse ) ,
75+ _ => return Err ( CheckHealthError :: BadResponse ) ,
8476 } ;
8577
86- if data. indexing_statuses . is_empty ( ) {
78+ let Some ( status ) = data. indexing_statuses . first ( ) else {
8779 return Err ( CheckHealthError :: DeploymentNotFound ) ;
88- }
89-
90- let status = & data. indexing_statuses [ 0 ] ;
80+ } ;
9181 let health_response = match status. health {
9282 health_query:: Health :: healthy => json ! ( { "health" : status. health } ) ,
9383 health_query:: Health :: unhealthy => {
0 commit comments