Skip to content

Commit 4bda059

Browse files
committed
optimize OpenRouter error message
1 parent 8215ab4 commit 4bda059

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

src/BE/Controllers/Chats/Chats/ChatController.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
using ModelContextProtocol.Protocol;
2020
using OpenAI.Chat;
2121
using System.ClientModel;
22+
using System.ClientModel.Primitives;
2223
using System.Diagnostics;
2324
using System.Security.Cryptography;
2425
using System.Text.Json;
@@ -707,7 +708,15 @@ async Task<Step> RunOne(List<OpenAIChatMessage> messageToSend)
707708
catch (ClientResultException e)
708709
{
709710
icc.FinishReason = DBFinishReason.UpstreamError;
710-
errorText = e.Message;
711+
PipelineResponse? pr = e.GetRawResponse();
712+
if (pr != null)
713+
{
714+
errorText = pr.Content.ToString();
715+
}
716+
else
717+
{
718+
errorText = e.Message;
719+
}
711720
logger.LogError(e, "Upstream error: {userMessageId}", req.LastMessageId);
712721
}
713722
catch (AggregateException e) when (e.InnerException is TaskCanceledException)

0 commit comments

Comments
 (0)