From 9c0f824ad7cc15412a3868411201a2e674fdea17 Mon Sep 17 00:00:00 2001 From: Sky Young Date: Tue, 22 May 2018 13:33:20 -0700 Subject: [PATCH] Add errors for block header undefined results --- lib/blocks.js | 15 ++++++++++++++- package.json | 2 +- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/lib/blocks.js b/lib/blocks.js index db73b22..a4f9a6f 100644 --- a/lib/blocks.js +++ b/lib/blocks.js @@ -79,7 +79,8 @@ BlockController.prototype.block = function(req, res, next) { self._block.getBlock(hash, function(err, block) { if (err) { return self.common.handleErrors(err, res); - } else if (!block) { + } + if (!block) { return self.common.handleErrors(new Error('block not in index'), res); } @@ -88,7 +89,16 @@ BlockController.prototype.block = function(req, res, next) { return self.common.handleErrors(err, res); } + if (!info) { + return self.common.handleErrors(new Error('block header info undefined'), res) + } + var blockResult = self.transformBlock(block, info); + + if (!blockResult) { + return self.common.handleErrors(new Error('blockResult from transformBlock undefined'), res) + } + if (blockResult.confirmations >= self.blockCacheConfirmations) { self.blockCache.set(hash, blockResult); } @@ -134,6 +144,9 @@ BlockController.prototype._normalizePrevHash = function(hash) { }; BlockController.prototype.transformBlock = function(block, info) { + if (!block || !info){ + return undefined; + } var transactionIds = block.txs.map(function(tx) { return tx.txid(); diff --git a/package.json b/package.json index adf6236..5458a21 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "flosight-api", "description": "A Florincoin blockchain REST and web socket API service for Flocore Node.", - "version": "5.0.0-beta.66", + "version": "5.0.0-beta.67", "repository": "git://github.com/bitpay/flosight-api.git", "bugs": { "url": "https://github.com/bitpay/flosight-api/issues"