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 version of SignalR
Why doesn't this actually do anything on the client when I throw an error in my Hub?
$.connection.hub.error(function() { return alert("test"); });
When I debug, I can see my error method being wired up, but when I throw an exception on the Hub, I can see there's never any attempt to call the method I setup above. The only thing that happens is SignalR barfs the error to the console.
For the record, I can wire up other events just fine
//Called during exceptions just fine
$.connection.hub.received(function() {
return alert("Received Data");
});
//Seems to do nothing?
$.connection.hub.error(function() {
return alert("Received Exception");
});
$.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 overrideHubPipelineModule.BuildIncoming
orHubPipelineModule.OnIncomingError
which can then be added to theHubPipeline
viaGlobalHost.HubPipeline.AddModule(myHubPipelineModule)
.https://github.com/SignalR/SignalR/issues/548
https://github.com/SignalR/SignalR/commit/83fdbfd9baa1f1cc3399d7f210cb062597c8084c
Example implementation: