How to prevent signalR errors from stopping further execution of javascript

Lars Höppner

Not completely sure what you're asking for, but here are my thoughts - your basic tools are ...

  1. checking for problematic conditions

    if (messageHub) { 
        // set up client hub methods and start connection ...   
    } else {
        // /signalr/hubs script didn't load properly, so skip setting up signalr
  2. using try/catch (for things that might cause problems but are less predictable); read jquery.signalR-* to see which errors might get thrown by the SignalR code

  3. a global error handler using window.onerror (also see this SO post):

    window.onerror = function(message, url, lineNumber) {

I had this problem as well. An easy way is to set a boolean in your done callback.

connected = true;

Then check before every request.

I have wrote me a lib that handel all my SignalR stuff and give me success and error callbacks. In this case I would get an errorCallback with content "not connected" or something. With a lib you have to write it only once.