From b3ebd84af54ff9d770bc3766fe74b55b25181360 Mon Sep 17 00:00:00 2001 From: leo Date: Wed, 20 Nov 2024 19:44:58 +0800 Subject: [PATCH] enhance: outputs the response body if OpenAI fails Signed-off-by: leo --- src/Models/OpenAI.cs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/Models/OpenAI.cs b/src/Models/OpenAI.cs index c5ca7449..58f26792 100644 --- a/src/Models/OpenAI.cs +++ b/src/Models/OpenAI.cs @@ -169,12 +169,15 @@ namespace SourceGit.Models task.Wait(cancellation); var rsp = task.Result; - if (!rsp.IsSuccessStatusCode) - throw new Exception($"AI service returns error code {rsp.StatusCode}"); - var reader = rsp.Content.ReadAsStringAsync(cancellation); reader.Wait(cancellation); + var body = reader.Result; + if (!rsp.IsSuccessStatusCode) + { + throw new Exception($"AI service returns error code {rsp.StatusCode}. Body: {body??string.Empty}"); + } + return JsonSerializer.Deserialize(reader.Result, JsonCodeGen.Default.OpenAIChatResponse); } catch