Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[SignalR] How to use IHubFilter to catch exceptions #30023

Unanswered
MathiasNysomFlohr asked this question in Q&A
Discussion options

We are creating a generalized way to catch and handle exceptions in our Hubs to ensure clean exists.
We are currently ending all our hubs in a method inspired by https://stackoverflow.com/questions/59020363/try-catch-using-iasyncenumerable-in-signalr-asp-net-core-3-0.

We want to move the relevant code to a HubFilter to keep the Hub clean and ensure error handling is done similarly across hubs.

We have tried building a IHubFilter with the following InvokeMethodAsync:

public async ValueTask<object?> InvokeMethodAsync(HubInvocationContext invocationContext, Func<HubInvocationContext, ValueTask<object?>> next)
{
 var res = await next(invocationContext);
 if (res is IAsyncEnumerable<IStreamResponse> asyncRes)
 {
 return Add(asyncRes);
 }
 return res;
}
private async IAsyncEnumerable<IStreamResponse> Add(IAsyncEnumerable<IStreamResponse> enumerable)
{
 [... run through enumerator...]
}

However, it seems that we do not get into the Add-method, and we don't hit any breakpoints in the lower leves of the enumerable. If we return res or asyncRes, we hit these breakpoints.

It seems like SignalR does not handle the new IAsyncEnumerable from the Add-method.

How can we solve this, so we are able to have generalized error handling?

Thank you for your time.

You must be logged in to vote

Replies: 1 comment

Comment options

Created in the wrong repo. Moved here: dotnet/aspnetcore#49993

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant

AltStyle によって変換されたページ (->オリジナル) /