Add exception handler pipeline behavior
See original GitHub issueI think there’s a place for an IRequestExceptionHandler
in the vein of IPreRequestProcessor
and IPostRequestProcessor
.
It would have a single method to implement
Task Handle(
TRequest request,
Exception exception,
ExceptionHandlerState<TResponse> state,
CancellationToken cancellationToken
)
The state object would work like this
public class RequestExceptionHandlerState<TResponse>
{
public TResponse Response { get; private set; }
public bool Handled { get; private set; }
public void SetHandled(TResponse response = default)
{
Handled = true;
Response = response;
}
}
Here’s my use case for it. I have certain requests that update a database using Entity Framework Core. One project has the implementation in a request handler with no specific DB provider dependency/reference. I have another layer that implements the specific DB provider and naming. The exception is thrown as a type from the DB provider library. With a IRequestExceptionHandler
, I can intercept the exception, do some DB specific logic and throw a domain specific exception.
Thoughts?
P.S.
I thought if this is in the main library, I could do some work to resolve IRequestExceptionHandler
s based on the type of the exception similar to how catch
blocks work, but I would need the ServiceFactory
.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:4
- Comments:9 (8 by maintainers)
Top GitHub Comments
Fixed by #339
Is there any traction on getting this exception handling code released? I’d like to make a handler that sends the exception to application insights.