-
Notifications
You must be signed in to change notification settings - Fork 45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Document examples of error handling with the different async interception options #18
Comments
@DaEkstrim I've just been looking at this and it's relatively complicated. So I've given a stab at helper base class to simplify exception handling. Have a look at TestSimpleAsyncInterceptor in the #20. Any feedback is appreciated. |
@JSkimming Thank you for looking into this. I should have been clearer in my original request. What I meant to say is that the documentation on the front page should make it clear that exception handling through As you said, yes it's a complex problem to solve as the execution flow varies vastly between |
@DaEkstrim I've further enhanced PR #20 to the pointy where I'm happy with the solution.
There needs to be two because the returned task is used to replace the return value of the Since these are both The base class An simple example could be as follows: public class ExceptionHandlingInterceptor : SimpleAsyncInterceptor
{
protected override async Task InterceptAsync(IInvocation invocation, Func<IInvocation, Task> proceed)
{
try
{
await proceed(invocation).ConfigureAwait(false);
}
catch (Exception e)
{
// Add custom handling of the exception here or, re-throw.
throw;
}
}
protected override async Task<T> InterceptAsync<T>(IInvocation invocation, Func<IInvocation, Task<T>> proceed)
{
try
{
return await proceed(invocation).ConfigureAwait(false);
}
catch (Exception e)
{
// Add custom handling of the exception here, or re-throw.
throw;
}
}
} What do you think? |
Also, I'm note sure about the name |
@DaEkstrim I've just pushed a version 1.4 to NuGet. I've also updated the documentation on how best to perform exception handling. |
@JSkimming Apologies for taking long to get back to you. I haven't yet got a chance to test your new updated version, due to personal commitments, however I have a task on my JIRA so it's definitely on my next things to do. With regards to the name, Edit: I just saw that you changed the name to |
@DaEkstrim Yes, having now given it greater consideration, I think this could be the default way in which people intercept invocations. It's why I placed it as option 1. I could go back and update the other two abstract classes, but that would have been a breaking change and it wouldn't have enhanced things in any way, so I decided to leave them as is. I'd love to hear how things work out for you. It's great to know my library is getting use out there in the wild 😃 |
@JSkimming So I finally got some spare time to convert my code to use version 1.4.0, using Option 1:
Am I missing something? Edit: Alrite, so I downloaded the repository to look into how the tests are being executed, and I found that it is using a custom extension method |
@DaEkstrim AsyncInterceptorBase isn't intended to implement How did you do it previously? Presumably you either implemented This library works by requiring you to provide an implementation of
All these extension methods are intended to reflect exactly the methods on Can you share some sample code? |
@JSkimming Thanks for the response. Yes after downloading the source code and studying it, I found that it was the extension methods that were taking care of wrapping the
Where This means that I cannot use the extension methods provided to instantiate the interceptors, since the container's instantiation logic is (and should be) out of my reach. So what I did was take your implementation of
And register both the interceptor and the determination wrapper with the IoC, like this
where
This way the I know this is a lot, so if you want me to clarify anything which I wasn't clear enough on, let me know and I'll elaborate. |
@JSkimming I actually found a simpler solution for the generic
This way I achieved the same thing as I stated in the above post AND I get to keep your implementation as is. |
@DaEkstrim I see. That's great, glad you got it working. |
I suggest that in the README.md, some examples on exception handling (such as logging an exception to Trace) are added, because I think that when using the ProcessingAsyncInterceptor option, this is not possible, and thus it would help the package users to understand better which option to use.
The text was updated successfully, but these errors were encountered: