Skip to content

Commit

Permalink
Improve error handling.
Browse files Browse the repository at this point in the history
  • Loading branch information
seungjlee committed Jan 2, 2018
1 parent 21a2d01 commit a7c452a
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 7 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Expand Up @@ -61,4 +61,6 @@ typings/
data/

# Configuration file
config.js
config.js
/package-lock.json
*.bak
36 changes: 30 additions & 6 deletions routes/account.js
Expand Up @@ -122,11 +122,19 @@ router.get('/:account', function(req, res, next)
async.waterfall([
function(callback)
{
web3.eth.getBlock("latest", false, function(err, result) { callback(err, result); });
try
{
web3.eth.getBlock("latest", false, function(err, result) { callback(err, result.number); });
}
catch(error)
{
console.log(error);
callback(error, 0);
}
},
function(lastBlock, callback)
function(lastBlockNumber, callback)
{
data.lastBlock = lastBlock.number;
data.lastBlock = lastBlockNumber;

if(data.lastBlock > kInitialMaxBlocks)
{
Expand All @@ -137,12 +145,28 @@ router.get('/:account', function(req, res, next)
data.fromBlock = 0;
}

web3.eth.getBalance(req.params.account, function(err, balance) { callback(err, balance); });
try
{
web3.eth.getBalance(req.params.account, function(err, balance) { callback(err, balance); });
}
catch(error)
{
console.log(error);
callback(error, 0);
}
},
function(balance, callback)
{
data.balance = balance;
web3.eth.getCode(req.params.account, function(err, code) { callback(err, code); });
try
{
web3.eth.getCode(req.params.account, function(err, code) { callback(err, code); });
}
catch(error)
{
console.log(error);
callback(error, "");
}
},
function(code, callback)
{
Expand All @@ -151,7 +175,7 @@ router.get('/:account', function(req, res, next)
{
data.isContract = true;
}

db.get(req.params.account.toLowerCase(), function(err, value) { callback(null, value); });
},
function(source, callback)
Expand Down

0 comments on commit a7c452a

Please sign in to comment.