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