enhance: outputs the response body if OpenAI fails
Some checks are pending
Continuous Integration / Package (push) Blocked by required conditions
Continuous Integration / Build (push) Waiting to run
Continuous Integration / Prepare version string (push) Waiting to run
Localization Check / localization-check (push) Waiting to run

Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
leo 2024-11-20 19:44:58 +08:00
parent efac161b12
commit b3ebd84af5
No known key found for this signature in database

View file

@ -169,12 +169,15 @@ namespace SourceGit.Models
task.Wait(cancellation); task.Wait(cancellation);
var rsp = task.Result; var rsp = task.Result;
if (!rsp.IsSuccessStatusCode)
throw new Exception($"AI service returns error code {rsp.StatusCode}");
var reader = rsp.Content.ReadAsStringAsync(cancellation); var reader = rsp.Content.ReadAsStringAsync(cancellation);
reader.Wait(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); return JsonSerializer.Deserialize(reader.Result, JsonCodeGen.Default.OpenAIChatResponse);
} }
catch catch