-
Notifications
You must be signed in to change notification settings - Fork 25.1k
[SignalR] How to use IHubFilter to catch exceptions #30023
-
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.
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 1 comment
-
Created in the wrong repo. Moved here: dotnet/aspnetcore#49993
Beta Was this translation helpful? Give feedback.