add handler for insight-error

This commit is contained in:
Matias Alejo Garcia 2014-08-27 17:50:28 -03:00
commit 8604fe27ca
3 changed files with 15 additions and 11 deletions

View file

@ -85,6 +85,7 @@ Network.prototype.connectedCopayers = function() {
};
Network.prototype._sendHello = function(copayerId) {
this.send(copayerId, {
type: 'hello',
copayerId: this.copayerId,
@ -224,13 +225,11 @@ Network.prototype._onMessage = function(enc) {
Network.prototype._setupConnectionHandlers = function(cb) {
preconditions.checkState(this.socket);
var self = this;
self.socket.on('connect', function() {
self.socket.on('disconnect', function() {
self.cleanUp();
});
if (typeof cb === 'function') cb();
self.socket.on('insight-error', function(m) {
console.log('** insgight-error', m);
self.emit('serverError');
});
self.socket.on('message', function(m) {
// delay execution, to improve error handling
setTimeout(function() {
@ -239,6 +238,13 @@ Network.prototype._setupConnectionHandlers = function(cb) {
});
self.socket.on('error', self._onError.bind(self));
self.socket.on('connect', function() {
self.socket.on('disconnect', function() {
self.cleanUp();
});
if (typeof cb === 'function') cb();
});
};
Network.prototype._onError = function(err) {
@ -342,7 +348,6 @@ Network.prototype.send = function(dest, payload, cb) {
dest = this.getCopayerIds();
payload.isBroadcast = 1;
}
if (typeof dest === 'string')
dest = [dest];
@ -352,6 +357,7 @@ Network.prototype.send = function(dest, payload, cb) {
dest.forEach(function(to) {
//console.log('\t to ' + to);
var message = self.encode(to, payload);
self.socket.emit('message', message);
});
if (typeof cb === 'function') cb();