spring-projects / spring-ai

An Application Framework for AI Engineering
https://docs.spring.io/spring-ai/reference/index.html
Apache License 2.0
3.33k stars 858 forks source link

Fix error handler with using unsubscribed response body in exception message #1705

Closed jitokim closed 1 week ago

jitokim commented 2 weeks ago

Fix error handler with using unsubscribed response body in exception message in AnthropicApi class.

When an error occurs while calling the chatCompletionStream function, It's difficult to know the cause.

AS-IS RuntimeException's message is a toString of an object (Mono<String>).

Response exception, Status: [401 UNAUTHORIZED], Body:[checkpoint("Body from POST https://api.anthropic.com/v1/messages [DefaultClientResponse]")]

image

TO-BE Replace the RuntimeException's message with the response body.

Response exception, Status: [401 UNAUTHORIZED], Body:[{"type":"error","error":{"type":"authentication_error","message":"invalid x-api-key"}}]

image
markpollack commented 1 week ago

Thanks! merged in fb2e7528d0b74ae4adcb4aa6e18436bff2e808e5