Add support for a func exception handler
diff --git a/src/DotPulsar/Abstractions/IPulsarClientBuilder.cs b/src/DotPulsar/Abstractions/IPulsarClientBuilder.cs
index aea21b0..3010b84 100644
--- a/src/DotPulsar/Abstractions/IPulsarClientBuilder.cs
+++ b/src/DotPulsar/Abstractions/IPulsarClientBuilder.cs
@@ -14,6 +14,7 @@
using System;
using System.Security.Cryptography.X509Certificates;
+using System.Threading.Tasks;
namespace DotPulsar.Abstractions
{
@@ -43,6 +44,11 @@
IPulsarClientBuilder ExceptionHandler(IHandleException exceptionHandler);
/// <summary>
+ /// Register a custom exception handler that will be invoked before the default exception handler.
+ /// </summary>
+ IPulsarClientBuilder ExceptionHandler(Func<ExceptionContext, ValueTask> exceptionHandler);
+
+ /// <summary>
/// The time to wait before retrying an operation or a reconnect. The default is 3 seconds.
/// </summary>
IPulsarClientBuilder RetryInterval(TimeSpan interval);
diff --git a/src/DotPulsar/Internal/FuncExceptionHandler.cs b/src/DotPulsar/Internal/FuncExceptionHandler.cs
new file mode 100644
index 0000000..6e22d97
--- /dev/null
+++ b/src/DotPulsar/Internal/FuncExceptionHandler.cs
@@ -0,0 +1,15 @@
+using DotPulsar.Abstractions;
+using System;
+using System.Threading.Tasks;
+
+namespace DotPulsar.Internal
+{
+ public sealed class FuncExceptionHandler : IHandleException
+ {
+ private readonly Func<ExceptionContext, ValueTask> _exceptionHandler;
+
+ public FuncExceptionHandler(Func<ExceptionContext, ValueTask> exceptionHandler) => _exceptionHandler = exceptionHandler;
+
+ public ValueTask OnException(ExceptionContext exceptionContext) => _exceptionHandler(exceptionContext);
+ }
+}
diff --git a/src/DotPulsar/Internal/PulsarClientBuilder.cs b/src/DotPulsar/Internal/PulsarClientBuilder.cs
index e9d9db8..c2a61f5 100644
--- a/src/DotPulsar/Internal/PulsarClientBuilder.cs
+++ b/src/DotPulsar/Internal/PulsarClientBuilder.cs
@@ -19,6 +19,7 @@
using System.Collections.Generic;
using System.Security.Cryptography.X509Certificates;
using System.Text;
+using System.Threading.Tasks;
namespace DotPulsar.Internal
{
@@ -76,6 +77,12 @@
return this;
}
+ public IPulsarClientBuilder ExceptionHandler(Func<ExceptionContext, ValueTask> exceptionHandler)
+ {
+ _exceptionHandlers.Add(new FuncExceptionHandler(exceptionHandler));
+ return this;
+ }
+
public IPulsarClientBuilder RetryInterval(TimeSpan interval)
{
_retryInterval = interval;