Skip to content

Commit a9673d1

Browse files
committed
[sidecar] better error handling for anthropic
we were eating some errors
1 parent 33933a2 commit a9673d1

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

llm_client/src/clients/anthropic.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,12 @@ impl AnthropicClient {
482482
return Err(LLMClientError::UnauthorizedAccess);
483483
}
484484

485+
if let Err(e) = response_stream.error_for_status_ref() {
486+
let body = response_stream.text().await?;
487+
println!("anthropic::err {body}");
488+
return Err(e.into());
489+
}
490+
485491
let mut event_source = response_stream.bytes_stream().eventsource();
486492

487493
// let event_next = event_source.next().await;
@@ -755,6 +761,12 @@ impl LLMClient for AnthropicClient {
755761
return Err(LLMClientError::UnauthorizedAccess);
756762
}
757763

764+
if let Err(e) = response_stream.error_for_status_ref() {
765+
let body = response_stream.text().await?;
766+
println!("anthropic::err {body}");
767+
return Err(e.into());
768+
}
769+
758770
let mut event_source = response_stream.bytes_stream().eventsource();
759771

760772
let mut input_tokens = 0;
@@ -893,6 +905,12 @@ impl LLMClient for AnthropicClient {
893905
return Err(LLMClientError::UnauthorizedAccess);
894906
}
895907

908+
if let Err(e) = response.error_for_status_ref() {
909+
let body = response.text().await?;
910+
println!("anthropic::err {body}");
911+
return Err(e.into());
912+
}
913+
896914
let mut response_stream = response.bytes_stream().eventsource();
897915

898916
let mut buffered_string = "".to_owned();

0 commit comments

Comments
 (0)