This is more of two questions, but :
What\'s the best way to have a top level exception handler for my Hub? It doesn\'t seem possible with the current vers
$.connection.hub.error is used to handle hub connection failures. You can use jQuery's deferred.fail() to handle an exception thrown from a particular hub invocation ($.connection.hub.methodThatThrows().fail(function() { ... }), but this obviously doesn't handle exceptions thrown from any invocation.
SignalR v1.0.0 will add support for IHubPipelineModules. Then you will be able to override HubPipelineModule.BuildIncoming or HubPipelineModule.OnIncomingError which can then be added to the HubPipeline via GlobalHost.HubPipeline.AddModule(myHubPipelineModule).
https://github.com/SignalR/SignalR/issues/548
https://github.com/SignalR/SignalR/commit/83fdbfd9baa1f1cc3399d7f210cb062597c8084c
Example implementation:
using Microsoft.AspNet.SignalR.Hubs;
public class MyHubPipelineModule : HubPipelineModule
{
protected override void OnIncomingError(ExceptionContext exceptionContext,
IHubIncomingInvokerContext invokerContext)
{
dynamic caller = invokerContext.Hub.Clients.Caller;
caller.ExceptionHandler(exceptionContext.Error.Message);
}
}
protected void Application_Start()
{
GlobalHost.HubPipeline.AddModule(new MyHubPipelineModule());
}
// JS
// hub.client is also introduced in SignalR v1.0.0
$.connection.myHub.client.exceptionHandler = function (message) {
alert(message);
};