fix: yield error when initial stream response is not successful

This commit is contained in:
Stevan Freeborn committed 2024-07-19 21:15:59 -05:00
1 parent 0a692d1b9a
commit 3b47ed3fb4
2 files changed
+46

No files matched your search

@@ -95,6 +95,14 @@ public class AnthropicApiClient : IAnthropicApiClient
public async IAsyncEnumerable<AnthropicEvent> CreateMessageAsync(StreamMessageRequest request)
{
var response = await SendRequestAsync(request);
if (response.IsSuccessStatusCode is false)
{
var error = Deserialize<AnthropicError>(await response.Content.ReadAsStringAsync()) ?? new AnthropicError();
yield return new AnthropicEvent(EventType.Error, new ErrorEventData(error.Error));
yield break;
}
var anthropicHeaders = new AnthropicHeaders(response.Headers);
using var responseContent = await response.Content.ReadAsStreamAsync();