Class ExceptionBehavior<TMessage, TResponse>
Pipeline behavior that catches unhandled exceptions from handlers and converts them to Error.InternalServerError failures. This is a safety net — handlers should not throw, but if they do, this prevents unhandled exceptions from escaping the mediator pipeline.
public sealed class ExceptionBehavior<TMessage, TResponse> : IPipelineBehavior<TMessage, TResponse> where TMessage : IMessage where TResponse : IResult, IFailureFactory<TResponse>
Type Parameters
TMessageThe message type.
TResponseThe response type, constrained to IResult and IFailureFactory<TSelf>.
- Inheritance
-
ExceptionBehavior<TMessage, TResponse>
- Implements
-
IPipelineBehavior<TMessage, TResponse>
- Inherited Members
- Extension Methods
Constructors
ExceptionBehavior(ILogger<ExceptionBehavior<TMessage, TResponse>>)
Initializes a new instance of the ExceptionBehavior<TMessage, TResponse> class.
public ExceptionBehavior(ILogger<ExceptionBehavior<TMessage, TResponse>> logger)
Parameters
loggerILogger<ExceptionBehavior<TMessage, TResponse>>The logger instance.
Methods
Handle(TMessage, MessageHandlerDelegate<TMessage, TResponse>, CancellationToken)
public ValueTask<TResponse> Handle(TMessage message, MessageHandlerDelegate<TMessage, TResponse> next, CancellationToken cancellationToken)
Parameters
messageTMessagenextMessageHandlerDelegate<TMessage, TResponse>cancellationTokenCancellationToken
Returns
- ValueTask<TResponse>