Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SignalR - Exceptions Propagation to Client

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.");       
}
like image 913
ronag Avatar asked Jul 30 '13 14:07

ronag


1 Answers

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).

like image 141
N. Taylor Mullen Avatar answered Oct 04 '22 10:10

N. Taylor Mullen