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();