Skip to content

Commit 852a9e0

Browse files
author
grokspice
committed
fix(search): report an unreadable error body instead of dropping it
A non-2xx /v1/search response had its body read with unwrap_or_default(), so a failure to read the body collapsed to an empty string and SearchFailed rendered as though the runtime had explained nothing — losing the transport error. Keep the status code, which is already known, and put the read failure in the body instead. The six pre-existing call sites in QueryHttpClient share the pattern and are tracked separately in #87.
1 parent 86176b9 commit 852a9e0

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

src/query.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -792,10 +792,17 @@ impl QueryHttpClient {
792792
if status_code != 200 {
793793
// The runtime explains search failures in a plain-text body ("No
794794
// data sources provided"). Surface it, not just the status code.
795-
let response_body = response.text().await.unwrap_or_default();
795+
let response_body = match response.text().await {
796+
Ok(body) => body.trim().to_string(),
797+
// The status code is already known, so a body that cannot be read
798+
// reports why instead of collapsing to an empty string — otherwise
799+
// the transport failure is lost and the error reads as if the
800+
// runtime had explained nothing.
801+
Err(e) => format!("<error body could not be read: {e}>"),
802+
};
796803
return Err(SearchError::SearchFailed {
797804
status_code,
798-
response_body: response_body.trim().to_string(),
805+
response_body,
799806
});
800807
}
801808

0 commit comments

Comments
 (0)