more error handling
This commit is contained in:
parent
f619192708
commit
465e4698f6
|
@ -19,10 +19,12 @@ exports.address = function(req, res, next, addr) {
|
||||||
}
|
}
|
||||||
|
|
||||||
a.update(function(err) {
|
a.update(function(err) {
|
||||||
if (err) return common.handleErrors(err, res, next);
|
if (err)
|
||||||
|
return common.handleErrors(err, res);
|
||||||
req.address = a;
|
else {
|
||||||
return next();
|
req.address = a;
|
||||||
|
return next();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -13,10 +13,12 @@ var mongoose = require('mongoose'),
|
||||||
*/
|
*/
|
||||||
exports.block = function(req, res, next, hash) {
|
exports.block = function(req, res, next, hash) {
|
||||||
Block.fromHashWithInfo(hash, function(err, block) {
|
Block.fromHashWithInfo(hash, function(err, block) {
|
||||||
if (err || ! block) return common.handleErrors(err, res, next);
|
if (err || ! block)
|
||||||
|
return common.handleErrors(err, res, next);
|
||||||
req.block = block.info;
|
else {
|
||||||
return next();
|
req.block = block.info;
|
||||||
|
return next();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
|
||||||
exports.handleErrors = function (err, res, next) {
|
exports.handleErrors = function (err, res) {
|
||||||
if (err) {
|
if (err) {
|
||||||
if (err.code) {
|
if (err.code) {
|
||||||
res.status(400).send(err.message + '. Code:' + err.code);
|
res.status(400).send(err.message + '. Code:' + err.code);
|
||||||
|
@ -9,10 +9,8 @@ exports.handleErrors = function (err, res, next) {
|
||||||
else {
|
else {
|
||||||
res.status(503).send(err.message);
|
res.status(503).send(err.message);
|
||||||
}
|
}
|
||||||
return next();
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
res.status(404).send('Not found');
|
res.status(404).send('Not found');
|
||||||
return next();
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -4,7 +4,8 @@
|
||||||
* Module dependencies.
|
* Module dependencies.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var Status = require('../models/Status');
|
var Status = require('../models/Status'),
|
||||||
|
common = require('./common');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Status
|
* Status
|
||||||
|
@ -19,8 +20,11 @@ exports.show = function(req, res, next) {
|
||||||
var statusObject = Status.new();
|
var statusObject = Status.new();
|
||||||
|
|
||||||
var returnJsonp = function (err) {
|
var returnJsonp = function (err) {
|
||||||
if(err) return next(err);
|
if (err || ! statusObject)
|
||||||
res.jsonp(statusObject);
|
return common.handleErrors(err, res);
|
||||||
|
else {
|
||||||
|
res.jsonp(statusObject);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
switch(option) {
|
switch(option) {
|
||||||
|
|
|
@ -15,12 +15,12 @@ var common = require('./common');
|
||||||
*/
|
*/
|
||||||
exports.transaction = function(req, res, next, txid) {
|
exports.transaction = function(req, res, next, txid) {
|
||||||
Transaction.fromIdWithInfo(txid, function(err, tx) {
|
Transaction.fromIdWithInfo(txid, function(err, tx) {
|
||||||
|
if (err || ! tx)
|
||||||
if (err || ! tx) return common.handleErrors(err, res, next);
|
return common.handleErrors(err, res);
|
||||||
|
else {
|
||||||
|
req.transaction = tx.info;
|
||||||
req.transaction = tx.info;
|
return next();
|
||||||
return next();
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -7,15 +7,24 @@ angular.module('insight.status').controller('StatusController', ['$scope', '$rou
|
||||||
Status.get({
|
Status.get({
|
||||||
q: 'get' + q
|
q: 'get' + q
|
||||||
}, function(d) {
|
}, function(d) {
|
||||||
|
$rootScope.infoError = null;
|
||||||
angular.extend($scope, d);
|
angular.extend($scope, d);
|
||||||
|
}, function(e) {
|
||||||
|
if (e.status === 503) {
|
||||||
|
$rootScope.infoError = 'Backend Error. ' + e.data;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$rootScope.infoError = 'Unknown error:' + e.data;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.getSync = function() {
|
$scope.getSync = function() {
|
||||||
Sync.get({}, function(sync) {
|
Sync.get({}, function(sync) {
|
||||||
|
$rootScope.syncError = null;
|
||||||
$scope.sync = sync;
|
$scope.sync = sync;
|
||||||
}, function() {
|
}, function(e) {
|
||||||
$rootScope.flashMessage = 'Could not get sync information';
|
$rootScope.syncError = 'Could not get sync information' + e;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
}]);
|
}]);
|
||||||
|
|
|
@ -9,9 +9,10 @@
|
||||||
<h3>getInfo</h3>
|
<h3>getInfo</h3>
|
||||||
<table class="table table-striped" data-ng-init="getStatus('Info')">
|
<table class="table table-striped" data-ng-init="getStatus('Info')">
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr data-ng-show="!info">
|
<tr data-ng-show="!info && !infoError">
|
||||||
<td colspan="2" class="text-center">Loading...</td>
|
<td colspan="2" class="text-center">Loading...
|
||||||
</tr>
|
<tr data-ng-show="infoError">
|
||||||
|
<td colspan="2" class="text-danger">{{infoError}}
|
||||||
<tr>
|
<tr>
|
||||||
<td>Version</td>
|
<td>Version</td>
|
||||||
<td>{{info.version}}</td>
|
<td>{{info.version}}</td>
|
||||||
|
@ -65,8 +66,8 @@
|
||||||
<td>{{info.paytxfee}}</td>
|
<td>{{info.paytxfee}}</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>errors</td>
|
<td>infoErrors</td>
|
||||||
<td>{{info.errors}}</td>
|
<td>{{info.infoErrors}}</td>
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
@ -75,8 +76,8 @@
|
||||||
<h3>sync status</h3>
|
<h3>sync status</h3>
|
||||||
<table class="table table-striped" data-ng-init="getSync()">
|
<table class="table table-striped" data-ng-init="getSync()">
|
||||||
<tbody>
|
<tbody>
|
||||||
|
<tr data-ng-show="syncError">
|
||||||
|
<td colspan="2"> <span class="text-danger"> {{ syncError }} </span>
|
||||||
<tr data-ng-show="sync.error">
|
<tr data-ng-show="sync.error">
|
||||||
<td colspan="2"> <span class="text-danger"> {{ sync.err }} </span>
|
<td colspan="2"> <span class="text-danger"> {{ sync.err }} </span>
|
||||||
</tr>
|
</tr>
|
||||||
|
@ -125,9 +126,12 @@
|
||||||
<h3>getTxOutSetInfo</h3>
|
<h3>getTxOutSetInfo</h3>
|
||||||
<table class="table table-striped" data-ng-init="getStatus('TxOutSetInfo')">
|
<table class="table table-striped" data-ng-init="getStatus('TxOutSetInfo')">
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr data-ng-show="!txoutsetinfo">
|
<tr data-ng-show="!txoutsetinfo && !infoError">
|
||||||
<td colspan="2" class="text-center">Loading...</td>
|
<td colspan="2" class="text-center">Loading...</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
<tr data-ng-show="infoError">
|
||||||
|
<td colspan="2" class="text-danger">{{infoError}}</td>
|
||||||
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>Height</td>
|
<td>Height</td>
|
||||||
<td>{{txoutsetinfo.height}}</td>
|
<td>{{txoutsetinfo.height}}</td>
|
||||||
|
@ -166,9 +170,13 @@
|
||||||
<h3>getDifficulty</h3>
|
<h3>getDifficulty</h3>
|
||||||
<table class="table table-striped" data-ng-init="getStatus('Difficulty')">
|
<table class="table table-striped" data-ng-init="getStatus('Difficulty')">
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr data-ng-show="!difficulty">
|
<tr data-ng-show="!difficulty && !infoError">
|
||||||
<td colspan="2" class="text-center">Loading...</td>
|
<td colspan="2" class="text-center">Loading...</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
<tr data-ng-show="infoError">
|
||||||
|
<td colspan="2" class="text-danger">{{infoError}}</td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
<tr>
|
<tr>
|
||||||
<td>Difficulty</td>
|
<td>Difficulty</td>
|
||||||
<td>{{difficulty}}</td>
|
<td>{{difficulty}}</td>
|
||||||
|
@ -180,10 +188,14 @@
|
||||||
<h3>getLastBlockHash</h3>
|
<h3>getLastBlockHash</h3>
|
||||||
<table class="table table-striped" data-ng-init="getStatus('LastBlockHash')">
|
<table class="table table-striped" data-ng-init="getStatus('LastBlockHash')">
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr data-ng-show="!lastblockhash">
|
<tr data-ng-show="!lastblockhash && !infoError">
|
||||||
<td colspan="1" class="text-center">Loading...</td>
|
<td colspan="2" class="text-center">Loading...</td>
|
||||||
|
</tr>
|
||||||
|
<tr data-ng-show="infoError">
|
||||||
|
<td colspan="2" class="text-danger">{{infoError}}</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
|
<td>Last block hash</td>
|
||||||
<td>{{lastblockhash}}</td>
|
<td>{{lastblockhash}}</td>
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
|
|
Loading…
Reference in New Issue