How to handle SignalR server exception at client?

Viewed 23248

The error handler is added like this at client:

$.connection.hub.url = "/signalr";
$.connection.hub.logging = true;
$.connection.hub.error(function(error) {
    console.log('SignalrAdapter: ' + error);
});

$.connection.hub.start().done(function() { me.onStartDone(); });
// ...

At server it is:

hubConfiguration.EnableDetailedErrors = true;

Accordingly to the docs this should be enough.

At my exception throwing it just displays a log text for it and does not invoke the handler:

[18:18:19 GMT+0000()] SignalR: ... [[[my error description here]]] ... 

At my cshtml page:

<script src="~/Scripts/vendor/jquery.signalR-2.1.2.js"></script>
<script src="~/signalr/hubs"></script>

However if I attach an error handler to the method itself it is got called:

$.connection.operatorHub.server.myMethodName(someParam).fail(function(error) {
    console.log("Error handler called: " + error);
});

How to handle a general error?

UPDATE. The answer is below. Also see these:

Hope it helps someone.

2 Answers
Related