Skip to content

Commit ca37e84

Browse files
authored
Merge pull request #67 from LukaszFliegel/main
Added error message propagation to client.
2 parents e1ac5f4 + 75ea2e7 commit ca37e84

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
namespace GenerativeAI.Live.Events;
2+
3+
/// <summary>
4+
/// Provides error message event data.
5+
/// </summary>
6+
public class ErrorMessageEventArgs : EventArgs
7+
{
8+
/// <summary>
9+
/// Gets the payload of the received message.
10+
/// </summary>
11+
public string ErrorMessage { get; }
12+
13+
/// <devdoc>
14+
/// Initializes a new instance of the class.
15+
/// </devdoc>
16+
public ErrorMessageEventArgs(string errorMessage)
17+
{
18+
ErrorMessage = errorMessage;
19+
}
20+
}

src/GenerativeAI.Live/Models/MultiModalLiveClient.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.Text.Json;
77
using System.Text.Json.Serialization.Metadata;
88
using GenerativeAI.Core;
9+
using GenerativeAI.Live.Events;
910
using GenerativeAI.Live.Helper;
1011
using GenerativeAI.Live.Logging;
1112
using GenerativeAI.Types;
@@ -560,6 +561,11 @@ public async Task ConnectAsync(bool autoSendSetup = true,CancellationToken cance
560561
//log info.CloseStatusDescription
561562
_logger?.LogConnectionClosedWithInvalidPyload(info.CloseStatusDescription!);
562563
}
564+
else if (info.CloseStatus == WebSocketCloseStatus.InternalServerError && !string.IsNullOrEmpty(info.CloseStatusDescription))
565+
{
566+
_logger?.LogConnectionClosedWithError(info.Type, info.Exception!);
567+
Disconnected?.Invoke(this, new ErrorMessageEventArgs(info.CloseStatusDescription));
568+
}
563569
else
564570
{
565571
_logger?.LogConnectionClosed();

0 commit comments

Comments
 (0)