The error handler is added like this at client:
$.connection.hub.url = \"/signalr\";
$.connection.hub.logging = true;
$.connection.hub.error(function(error)
I tested on a little chat project (downloaded here) it seems this method handle only connection errors.
$.connection.hub.error(function(error) {
console.log('SignalrAdapter: ' + error);
});
I was able to handle all exceptions with the HubPipelineModule
class.
1) I created a SOHubPipelineModule
public class SOHubPipelineModule : HubPipelineModule
{
protected override void OnIncomingError(ExceptionContext exceptionContext,
IHubIncomingInvokerContext invokerContext)
{
dynamic caller = invokerContext.Hub.Clients.Caller;
caller.ExceptionHandler(exceptionContext.Error.Message);
}
}
2) I Added the module to GlobalHost.HubPipeline
// Any connection or hub wire up and configuration should go here
GlobalHost.HubPipeline.AddModule(new SOHubPipelineModule());
var hubConfiguration = new HubConfiguration { EnableDetailedErrors = true };
app.MapSignalR(hubConfiguration);
3) My ChatHub
class :
public class ChatHub : Hub
{
public void Send(string name, string message)
{
throw new Exception("exception for Artyom");
Clients.All.broadcastMessage(name, message);
}
}
4) In the js I use this code to get my exception message :
$.connection.chatHub.client.exceptionHandler = function (error) {
console.log('SignalrAdapter: ' + error);
alert('SignalrAdapter: ' + error);
};