In Web API all the exceptions can be cought by Middleware. In Asp.Net Core 5.0 Hub Filters will do that job.
But how to handle exceptions in Asp.Net Core 3.1 in SignalR hubs? Is there a sole way to write try/catch in every methods like below?
[Authorize]
public class OrdersHub : BaseHub
{
public async Task GetOrder(Guid requestId, int orderId)
{
try
{
var data = await ordersService.GetOrderAsync(orderId);
await Clients.Caller.SendAsync("GetOrderResult", requestId, result);
}
catch (Exception ex)
{
await Clients.Caller.Reject(requestId, ex);
}
}
}