scientistnik/btsdex

Handling errors

wmbutler opened this issue · 3 comments

Occasionally the socket is broken and this throws an error. I was hoping to catch this error and re-open a connection. Can you help me with the logic to do this reliably?

I'm calling my function loadRules() when 'connected' is seen.

Bitshares.subscribe('connected', loadRules);
Bitshares.connect();

I then make a call every 15 seconds

setInterval(loadRules,15*1000);

When the socket fails, I was hoping to catch the error and reconnect but this code does not work. My thinking here is that if loadRules throws an error the catch section would connect and resubscribe.

try {
    setInterval(loadRules,15*1000);
}
catch(e) {
    Bitshares.subscribe('connected', loadRules);
    Bitshares.connect();
}

I'm trying to reproduce. How long did this work before the socket fails?

Try it set BitShares.events.connected.init = false before BitShares.connect()

BitShares.events.connected.init = false;
BitShares.connect();

I think I will do reset function

For reconnect, please use BitShares.reconnect() function from btsdex v0.3.1.

I'm trying to reproduce. How long did this work before the socket fails?

The socket can disconnect arbitrarily. To reproduce, you can force a disconnect by disabling Internet access to your computer manually and observing the error. This is the state that I'm trying to recover from.