1
0
mirror of https://github.com/bigchaindb/bigchaindb.git synced 2024-06-28 00:27:45 +02:00

Problem: Unkown exceptions being handled

Solution: Handle only known exceptions
This commit is contained in:
kansi 2018-03-16 11:47:15 +05:30
parent 610e6f00f2
commit 5b3fab666d
3 changed files with 11 additions and 14 deletions

View File

@ -253,8 +253,9 @@ class BigchainDB(Bigchain):
return validators
except Exception:
raise Exception('Error while processing data from tendermint.')
except requests.exceptions.RequestException as e:
logger.error('Error while connecting to Tendermint HTTP API')
raise e
Block = namedtuple('Block', ('app_hash', 'height', 'transactions'))

View File

@ -1,8 +1,6 @@
from flask import current_app
from flask_restful import Resource
from bigchaindb.web.views.base import make_error
class ValidatorsApi(Resource):
def get(self):
@ -14,11 +12,7 @@ class ValidatorsApi(Resource):
pool = current_app.config['bigchain_pool']
try:
with pool() as bigchain:
validators = bigchain.get_validators()
with pool() as bigchain:
validators = bigchain.get_validators()
return validators
except Exception:
return make_error(500)
return validators

View File

@ -1,5 +1,7 @@
import pytest
from requests.exceptions import RequestException
pytestmark = pytest.mark.tendermint
VALIDATORS_ENDPOINT = '/api/v1/validators/'
@ -20,11 +22,11 @@ def test_get_validators_endpoint(b, client, monkeypatch):
def test_get_validators_500_endpoint(b, client, monkeypatch):
def mock_get(uri):
return 'InvalidResponse'
raise RequestException
monkeypatch.setattr('requests.get', mock_get)
res = client.get(VALIDATORS_ENDPOINT)
assert res.status_code == 500
with pytest.raises(RequestException):
client.get(VALIDATORS_ENDPOINT)
# Helper