better error API handling

This commit is contained in:
Matias Alejo Garcia 2014-01-20 16:11:35 -03:00
parent 4e1562ce7a
commit f619192708
5 changed files with 31 additions and 8 deletions

View File

@ -13,7 +13,7 @@ var mongoose = require('mongoose'),
*/
exports.block = function(req, res, next, hash) {
Block.fromHashWithInfo(hash, function(err, block) {
if (err || ! tx) return common.handleErrors(err, res, next);
if (err || ! block) return common.handleErrors(err, res, next);
req.block = block.info;
return next();

View File

@ -92,7 +92,6 @@ BlockSchema.statics.fromHashWithInfo = function(hash, cb) {
block.hash = hash;
block.getInfo(function(err, blockInfo) {
console.log('[Block.js.95:err:]',err); //TODO
if (err) return cb(err);
if (!blockInfo) return cb();

View File

@ -8,8 +8,16 @@ angular.module('insight.address').controller('AddressController', ['$scope', '$r
addrStr: $routeParams.addrStr
}, function(address) {
$scope.address = address;
}, function() {
$rootScope.flashMessage = 'Address Not Found';
}, function(e) {
if (e.status === 400) {
$rootScope.flashMessage = 'Invalid Address: ' + $routeParams.addrStr;
}
else if (e.status === 503) {
$rootScope.flashMessage = 'Backend Error. ' + e.data;
}
else {
$rootScope.flashMessage = 'Address Not Found';
}
$location.path('/');
});
};

View File

@ -17,8 +17,16 @@ angular.module('insight.blocks').controller('BlocksController', ['$scope', '$roo
blockHash: $routeParams.blockHash
}, function(block) {
$scope.block = block;
}, function() {
$rootScope.flashMessage = 'Block Not Found';
}, function(e) {
if (e.status === 400) {
$rootScope.flashMessage = 'Invalid Transaction ID: ' + $routeParams.txId;
}
else if (e.status === 503) {
$rootScope.flashMessage = 'Backend Error. ' + e.data;
}
else {
$rootScope.flashMessage = 'Block Not Found';
}
$location.path('/');
});
};

View File

@ -8,8 +8,16 @@ angular.module('insight.transactions').controller('transactionsController', ['$s
txId: $routeParams.txId
}, function(tx) {
$scope.tx = tx;
}, function() {
$rootScope.flashMessage = 'Transaction Not Found';
}, function(e) {
if (e.status === 400) {
$rootScope.flashMessage = 'Invalid Transaction ID: ' + $routeParams.txId;
}
else if (e.status === 503) {
$rootScope.flashMessage = 'Backend Error. ' + e.data;
}
else {
$rootScope.flashMessage = 'Transaction Not Found';
}
$location.path('/');
});
};