Merge pull request #302 from maraoz/feature/improve-error-messages

improve error messages + fix server error display
This commit is contained in:
Gustavo Maximiliano Cortez 2014-02-13 18:42:49 -02:00
commit e5216a4fe6
4 changed files with 69 additions and 48 deletions

View File

@ -136,11 +136,16 @@ A REST API is provided at /api. The entry points are:
/api/txs/?address=mmhmMNfBiZZ37g1tgg2t8DDbNoEdqKVxAL
```
### Sync status
### Historic blockchain data sync status
```
/api/sync
```
### Live network p2p data sync status
```
/api/peer
```
## Web Socket API
The web socket API is served using [socket.io](http://socket.io) at:
```

View File

@ -44,7 +44,9 @@ function spec() {
PeerSync.prototype.info = function() {
return {
connected: this.connected
connected: this.connected,
host: this.peerdb[0].ipv4,
port: this.peerdb[0].port
};
};

View File

@ -1,51 +1,52 @@
'use strict';
angular.module('insight.connection').controller('ConnectionController',
function($scope, $window, Status, getSocket, PeerSync) {
function($scope, $window, Status, getSocket, PeerSync) {
// Set initial values
$scope.apiOnline = true;
$scope.serverOnline = true;
$scope.clienteOnline = true;
var socket = getSocket($scope);
// Check for the node server connection
socket.on('disconnect', function() {
$scope.serverOnline = false;
});
socket.on('connect', function() {
// Set initial values
$scope.apiOnline = true;
$scope.serverOnline = true;
});
$scope.clienteOnline = true;
// Check for the api connection
$scope.getConnStatus = function() {
PeerSync.get({},
function(peer) {
$scope.apiOnline = peer.connected;
},
function() {
$scope.apiOnline = false;
var socket = getSocket($scope);
// Check for the node server connection
socket.on('connect', function() {
$scope.serverOnline = true;
socket.on('disconnect', function() {
$scope.serverOnline = false;
});
});
};
socket.emit('subscribe', 'sync');
socket.on('status', function(sync) {
// Check for the api connection
$scope.getConnStatus = function() {
PeerSync.get({},
function(peer) {
$scope.apiOnline = peer.connected;
$scope.host = peer.host;
$scope.port = peer.port;
},
function() {
$scope.apiOnline = false;
});
};
socket.emit('subscribe', 'sync');
socket.on('status', function(sync) {
$scope.apiOnline = (sync.status !== 'aborted' && sync.status !== 'error');
});
// Check for the client conneciton
$window.addEventListener('offline', function() {
$scope.$apply(function() {
$scope.clienteOnline = false;
});
}, true);
$window.addEventListener('online', function() {
$scope.$apply(function() {
$scope.clienteOnline = true;
});
}, true);
});
// Check for the client conneciton
$window.addEventListener('offline', function() {
$scope.$apply(function() {
$scope.clienteOnline = false;
});
}, true);
$window.addEventListener('online', function () {
$scope.$apply(function() {
$scope.clienteOnline = true;
});
}, true);
});

View File

@ -1,10 +1,23 @@
<div class="connection-status container" data-ng-controller="ConnectionController">
<!-- apiOnline disabled || !apiOnline -->
<div class="alert alert-danger" data-ng-show="!serverOnline || !clienteOnline || !apiOnline", data-ng-init="getConnStatus()">
<div class="alert alert-danger"
data-ng-show="!serverOnline || !clienteOnline || !apiOnline"
data-ng-init="getConnStatus()">
<strong>Error!</strong>
<p data-ng-show="!apiOnline">Can't connect to bitcoind.</p>
<p data-ng-show="!serverOnline">Can't connect to server.</p>
<p data-ng-show="!clienteOnline">Can't connect to internet. Please, check your connection.</p>
<p data-ng-show="!apiOnline">
Can't connect to bitcoind to get live updates from the p2p network.
(Tried connecting to bitcoind at {{host}}:{{port}} and failed.)
</p>
<p data-ng-show="!serverOnline">
Can't connect to insight server. Attempting to reconnect...
</p>
<p data-ng-show="!clienteOnline">
Can't connect to internet. Please, check your connection.
</p>
</div>
</div>