Reputation: 51263
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.");
}
Upvotes: 6
Views: 2822
Reputation: 18301
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).
Upvotes: 3