question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add exception handler pipeline behavior

See original GitHub issue

I 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 IRequestExceptionHandlers based on the type of the exception similar to how catch blocks work, but I would need the ServiceFactory.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:4
  • Comments:9 (8 by maintainers)

github_iconTop GitHub Comments

4reactions
jbogardcommented, Sep 18, 2019

Fixed by #339

1reaction
developermjcommented, Sep 14, 2019

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to define one specifc exception handler in Mediatr for ...
I add this exception handler to the (Autofac) dependency container and this works if I throw a MyException in the MyHandler for MyRequest...
Read more >
Validation without Exceptions using a MediatR Pipeline ...
This post will focus on validation in a Mediatr Pipeline behaviour. You may find a lot of code like this on StackOverflow, where...
Read more >
How to implement cross cutting concerns with MediatR ...
I have devised a pattern, which I think is acceptable utilising both Pipeline Behaviours and Middleware to handle exceptions in my Web API....
Read more >
Handle errors in ASP.NET Core
Discover how to handle errors in ASP. ... Developer exception page; Exception handler page; Exception handler lambda; UseStatusCodePages ...
Read more >
Advanced features of the MediatR package - Pipeline ...
It's a better solution to add a global exception handler middleware to the ASP.Net Core pipeline catching the unhandled exceptions and ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found