From 41d5826fee97de823248260ac0890f03ef87e007 Mon Sep 17 00:00:00 2001 From: Gary Pennington Date: Tue, 26 Mar 2024 16:18:37 +0000 Subject: [PATCH] [batching] fix subgraph unwrapping (#4849) Without this fix a null body would cause the router to panic. With this fix, if a body is null, then the router returns an error to the user. --- apollo-router/src/services/subgraph_service.rs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/apollo-router/src/services/subgraph_service.rs b/apollo-router/src/services/subgraph_service.rs index 654ca83881..cdf1e757de 100644 --- a/apollo-router/src/services/subgraph_service.rs +++ b/apollo-router/src/services/subgraph_service.rs @@ -805,12 +805,15 @@ pub(crate) async fn process_batch( } tracing::debug!("parts: {parts:?}, content_type: {content_type:?}, body: {body:?}"); - let value = serde_json::from_slice(&body.unwrap().unwrap()).map_err(|error| { - FetchError::SubrequestMalformedResponse { + let value = + serde_json::from_slice(&body.ok_or(FetchError::SubrequestMalformedResponse { + service: service.to_string(), + reason: "no body in response".to_string(), + })??) + .map_err(|error| FetchError::SubrequestMalformedResponse { service: service.to_string(), reason: error.to_string(), - } - })?; + })?; tracing::debug!("json value from body is: {value:?}"); @@ -1038,7 +1041,7 @@ pub(crate) async fn call_http( let (parts, _) = subgraph_request.into_parts(); let body = serde_json::to_string(&body).expect("JSON serialization should not fail"); - tracing::info!("our JSON body: {body:?}"); + tracing::debug!("our JSON body: {body:?}"); let mut request = http::Request::from_parts(parts, Body::from(body)); request