fix: OpenAI apis will now correctly print an error to the console if the request fails

This commit is contained in:
Kwoth
2025-02-02 12:52:25 +00:00
parent 02fa501530
commit 542cdc2d0d

View File

@@ -111,8 +111,20 @@ public partial class OpenAiApiSession : IChatterBotSession
}); });
var dataString = await data.Content.ReadAsStringAsync(); var dataString = await data.Content.ReadAsStringAsync();
try try
{ {
data.EnsureSuccessStatusCode();
}
catch (Exception ex)
{
Log.Error(ex, "Failed to get response from OpenAI: {Message}", ex.Message);
return new Error<string>("Failed to get response from OpenAI");
}
try
{
var response = JsonConvert.DeserializeObject<OpenAiCompletionResponse>(dataString); var response = JsonConvert.DeserializeObject<OpenAiCompletionResponse>(dataString);
// Log.Information("Received response: {Response} ", dataString); // Log.Information("Received response: {Response} ", dataString);