From 75ea2e74e7cfdc299fe63fb6383471772cda623d Mon Sep 17 00:00:00 2001 From: Lukasz Fliegel Date: Wed, 13 Aug 2025 13:26:05 +0200 Subject: [PATCH] Added error message porpagation to client. In case of quote extension, SDK disconnected client without any info why. --- .../Events/ErrorMessageEventArgs.cs | 20 +++++++++++++++++++ .../Models/MultiModalLiveClient.cs | 6 ++++++ 2 files changed, 26 insertions(+) create mode 100644 src/GenerativeAI.Live/Events/ErrorMessageEventArgs.cs diff --git a/src/GenerativeAI.Live/Events/ErrorMessageEventArgs.cs b/src/GenerativeAI.Live/Events/ErrorMessageEventArgs.cs new file mode 100644 index 0000000..54c6940 --- /dev/null +++ b/src/GenerativeAI.Live/Events/ErrorMessageEventArgs.cs @@ -0,0 +1,20 @@ +namespace GenerativeAI.Live.Events; + +/// +/// Provides error message event data. +/// +public class ErrorMessageEventArgs : EventArgs +{ + /// + /// Gets the payload of the received message. + /// + public string ErrorMessage { get; } + + /// + /// Initializes a new instance of the class. + /// + public ErrorMessageEventArgs(string errorMessage) + { + ErrorMessage = errorMessage; + } +} diff --git a/src/GenerativeAI.Live/Models/MultiModalLiveClient.cs b/src/GenerativeAI.Live/Models/MultiModalLiveClient.cs index f244435..a935acf 100644 --- a/src/GenerativeAI.Live/Models/MultiModalLiveClient.cs +++ b/src/GenerativeAI.Live/Models/MultiModalLiveClient.cs @@ -6,6 +6,7 @@ using System.Text.Json; using System.Text.Json.Serialization.Metadata; using GenerativeAI.Core; +using GenerativeAI.Live.Events; using GenerativeAI.Live.Helper; using GenerativeAI.Live.Logging; using GenerativeAI.Types; @@ -560,6 +561,11 @@ public async Task ConnectAsync(bool autoSendSetup = true,CancellationToken cance //log info.CloseStatusDescription _logger?.LogConnectionClosedWithInvalidPyload(info.CloseStatusDescription!); } + else if (info.CloseStatus == WebSocketCloseStatus.InternalServerError && !string.IsNullOrEmpty(info.CloseStatusDescription)) + { + _logger?.LogConnectionClosedWithError(info.Type, info.Exception!); + Disconnected?.Invoke(this, new ErrorMessageEventArgs(info.CloseStatusDescription)); + } else { _logger?.LogConnectionClosed();