diff --git a/CryptoExchange.Net/SocketClient.cs b/CryptoExchange.Net/SocketClient.cs index 642328e..f2bb669 100644 --- a/CryptoExchange.Net/SocketClient.cs +++ b/CryptoExchange.Net/SocketClient.cs @@ -158,6 +158,7 @@ namespace CryptoExchange.Net catch(Exception ex) { log.Write(LogVerbosity.Error, $"Socket {subscription.Socket.Id} Exception during message processing\r\nProcessor: {currentHandlerName}\r\nException: {ex}\r\nData: {data}"); + subscription.InvokeExceptionHandler(ex); } } diff --git a/CryptoExchange.Net/Sockets/SocketSubscription.cs b/CryptoExchange.Net/Sockets/SocketSubscription.cs index a5911c0..3031c83 100644 --- a/CryptoExchange.Net/Sockets/SocketSubscription.cs +++ b/CryptoExchange.Net/Sockets/SocketSubscription.cs @@ -12,6 +12,7 @@ namespace CryptoExchange.Net.Sockets { public event Action ConnectionLost; public event Action ConnectionRestored; + public event Action Exception; /// /// Message handlers for this subscription. Should return true if the message is handled and should not be distributed to the other handlers @@ -145,6 +146,11 @@ namespace CryptoExchange.Net.Sockets } } + public void InvokeExceptionHandler(Exception e) + { + Exception(e); + } + public async Task Close() { Socket.ShouldReconnect = false; diff --git a/CryptoExchange.Net/Sockets/UpdateSubscription.cs b/CryptoExchange.Net/Sockets/UpdateSubscription.cs index 7188679..ba872e9 100644 --- a/CryptoExchange.Net/Sockets/UpdateSubscription.cs +++ b/CryptoExchange.Net/Sockets/UpdateSubscription.cs @@ -25,6 +25,15 @@ namespace CryptoExchange.Net.Sockets remove => subscription.ConnectionRestored -= value; } + /// + /// Event when an exception happened + /// + public event Action Exception + { + add => subscription.Exception += value; + remove => subscription.Exception -= value; + } + /// /// The id of the socket ///