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

@ -120,7 +120,7 @@ angular.module('copayApp.controllers').controller('JoinController',
$scope.loading = false; $scope.loading = false;
if (err || !w) { if (err || !w) {
if (err === 'joinError') if (err === 'joinError')
notification.error('Can\'t find peer.'); notification.error('Fatal error connecting to Insight server');
else if (err === 'walletFull') else if (err === 'walletFull')
notification.error('The wallet is full'); notification.error('The wallet is full');
else if (err === 'badNetwork') else if (err === 'badNetwork')

View file

@ -207,7 +207,6 @@ WalletFactory.prototype.getWallets = function() {
WalletFactory.prototype.delete = function(walletId, cb) { WalletFactory.prototype.delete = function(walletId, cb) {
var s = this.storage; var s = this.storage;
this.log('## DELETING WALLET ID:' + walletId); //TODO
s.deleteWallet(walletId); s.deleteWallet(walletId);
s.setLastOpened(undefined); s.setLastOpened(undefined);
return cb(); return cb();
@ -257,7 +256,6 @@ WalletFactory.prototype.joinCreateSession = function(secret, nickname, passphras
self.network.start(opts, function() { self.network.start(opts, function() {
self.network.greet(s.pubKey); self.network.greet(s.pubKey);
self.network.on('data', function(sender, data) { self.network.on('data', function(sender, data) {
if (data.type === 'walletId') { if (data.type === 'walletId') {
if (data.networkName !== self.networkName) { if (data.networkName !== self.networkName) {

View file

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