I have a SignalR application with a .NET client. When an error occurs at the server I need to be able to handle this on client side. However, this is a bit difficult as Signalr always wraps all exceptions into an "InvalidOperationException" with a message like "UnknownUserException was thrown...", instead of actually giving me the UnknownUserException
.
I'm not sure how to go about this?
An example which doesn't work right now (since InvalidOperationException
is thrown instead of the actualy exception):
try
{
await this.hubProxy.Invoke<Guid>("Authenticate", nww object[] { userName, languageCode, credentials });
}
catch(UnknownUserException ex)
{
Toast.Dislay("Invalid UserName.");
}
catch(ConnectionError ex)
{
Toast.Dislay("Connection Error.");
}
On your server you can enable detailed errors:
Routes.RouteTable.MapHubs(new HubConfiguration
{
EnableDetailedErrors = true
});
Keep in mind, by doing this errors thrown on the server will be passed over to clients which may reveal some unintended vulnerabilities in your server side implementation (just an FYI).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With