From a9673d13e165688e3b27b4d12a16772821055611 Mon Sep 17 00:00:00 2001 From: maan2003 Date: Tue, 25 Feb 2025 11:21:44 +0530 Subject: [PATCH] [sidecar] better error handling for anthropic we were eating some errors --- llm_client/src/clients/anthropic.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/llm_client/src/clients/anthropic.rs b/llm_client/src/clients/anthropic.rs index ac28681ff..3c6e29cf4 100644 --- a/llm_client/src/clients/anthropic.rs +++ b/llm_client/src/clients/anthropic.rs @@ -482,6 +482,12 @@ impl AnthropicClient { return Err(LLMClientError::UnauthorizedAccess); } + if let Err(e) = response_stream.error_for_status_ref() { + let body = response_stream.text().await?; + println!("anthropic::err {body}"); + return Err(e.into()); + } + let mut event_source = response_stream.bytes_stream().eventsource(); // let event_next = event_source.next().await; @@ -755,6 +761,12 @@ impl LLMClient for AnthropicClient { return Err(LLMClientError::UnauthorizedAccess); } + if let Err(e) = response_stream.error_for_status_ref() { + let body = response_stream.text().await?; + println!("anthropic::err {body}"); + return Err(e.into()); + } + let mut event_source = response_stream.bytes_stream().eventsource(); let mut input_tokens = 0; @@ -893,6 +905,12 @@ impl LLMClient for AnthropicClient { return Err(LLMClientError::UnauthorizedAccess); } + if let Err(e) = response.error_for_status_ref() { + let body = response.text().await?; + println!("anthropic::err {body}"); + return Err(e.into()); + } + let mut response_stream = response.bytes_stream().eventsource(); let mut buffered_string = "".to_owned();