From 542cdc2d0d27a9d6e540f61ff7cce0c9b2c63631 Mon Sep 17 00:00:00 2001 From: Kwoth Date: Sun, 2 Feb 2025 12:52:25 +0000 Subject: [PATCH] fix: OpenAI apis will now correctly print an error to the console if the request fails --- .../Games/ChatterBot/_common/OpenAiApiSession.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/NadekoBot/Modules/Games/ChatterBot/_common/OpenAiApiSession.cs b/src/NadekoBot/Modules/Games/ChatterBot/_common/OpenAiApiSession.cs index c093bf6ce..e3d0ce08e 100644 --- a/src/NadekoBot/Modules/Games/ChatterBot/_common/OpenAiApiSession.cs +++ b/src/NadekoBot/Modules/Games/ChatterBot/_common/OpenAiApiSession.cs @@ -111,8 +111,20 @@ public partial class OpenAiApiSession : IChatterBotSession }); var dataString = await data.Content.ReadAsStringAsync(); + try { + data.EnsureSuccessStatusCode(); + } + catch (Exception ex) + { + Log.Error(ex, "Failed to get response from OpenAI: {Message}", ex.Message); + return new Error("Failed to get response from OpenAI"); + } + + try + { + var response = JsonConvert.DeserializeObject(dataString); // Log.Information("Received response: {Response} ", dataString);