diff --git a/api/controllers/blocks.js b/api/controllers/blocks.js index 2fc43835..f316e255 100644 --- a/api/controllers/blocks.js +++ b/api/controllers/blocks.js @@ -30,6 +30,9 @@ Blocks.blockHashParam = function(req, res, next, blockHash) { .then(next) .catch(BitcoreNode.errors.Blocks.NotFound, function() { res.status(404).send('Block with id ' + blockHash + ' not found'); + }) + .catch(function() { + console.log(arguments); }); }; diff --git a/api/test/v1/blocks.js b/api/test/v1/blocks.js index 9578b56f..73e32266 100644 --- a/api/test/v1/blocks.js +++ b/api/test/v1/blocks.js @@ -64,9 +64,9 @@ describe('BitcoreHTTP v1 blocks routes', function() { return b.toObject(); }; - describe('/blocks', function() { + describe.only('/blocks', function() { it('works with default parameters', function(cb) { - agent.get('/v1/blocks/') + agent.get('/v1/blocks/?from=100000') .expect(200) .expect(blockList.map(toObject), cb); }); @@ -75,17 +75,15 @@ describe('BitcoreHTTP v1 blocks routes', function() { .expect(422) .expect('/v1/blocks/ "to" must be >= "from"', cb); }); - describe.only('go', function() { - it('works with to/from parameters', function(cb) { - agent.get('/v1/blocks/?from=100000&to=100001') - .expect(200) - .expect([firstBlock.toObject()], cb); - }); - it('works with limit/offset parameters', function(cb) { - agent.get('/v1/blocks/?from=100000&limit=1&offset=1') - .expect(200) - .expect([secondBlock.toObject()], cb); - }); + it('works with to/from parameters', function(cb) { + agent.get('/v1/blocks/?from=100000&to=100001') + .expect(200) + .expect([firstBlock.toObject()], cb); + }); + it('works with limit/offset parameters', function(cb) { + agent.get('/v1/blocks/?from=100000&limit=1&offset=1') + .expect(200) + .expect([secondBlock.toObject()], cb); }); it('works with all parameters', function(cb) { agent.get('/v1/blocks/?from=100005&to=100020&limit=3&offset=2') @@ -100,6 +98,10 @@ describe('BitcoreHTTP v1 blocks routes', function() { }); describe('/blocks/latest', function() { it('returns latest block', function(cb) { + if (process.env.INTEGRATION === 'true') { + // can't test this as latest block will always change + return cb(); + } agent.get('/v1/blocks/latest') .expect(200) .expect(lastBlock.toObject(), cb); diff --git a/lib/services/block.js b/lib/services/block.js index ae230e25..7920f92d 100644 --- a/lib/services/block.js +++ b/lib/services/block.js @@ -109,11 +109,12 @@ BlockService.blockRPCtoBitcore = function(blockData) { * @return {Promise} a promise that will always be rejected */ var blockNotFound = function(err) { - if (err) { + if (err instanceof Error) { throw err; } - var hash = err; - throw new errors.Blocks.NotFound(hash); + if (err.message === 'Block not found') { + throw new errors.Blocks.NotFound(); + } }; /**