mirror of
https://github.com/bigchaindb/bigchaindb.git
synced 2024-10-13 13:34:05 +00:00
Problem: Unkown exceptions being handled
Solution: Handle only known exceptions
This commit is contained in:
parent
610e6f00f2
commit
5b3fab666d
@ -253,8 +253,9 @@ class BigchainDB(Bigchain):
|
|||||||
|
|
||||||
return validators
|
return validators
|
||||||
|
|
||||||
except Exception:
|
except requests.exceptions.RequestException as e:
|
||||||
raise Exception('Error while processing data from tendermint.')
|
logger.error('Error while connecting to Tendermint HTTP API')
|
||||||
|
raise e
|
||||||
|
|
||||||
|
|
||||||
Block = namedtuple('Block', ('app_hash', 'height', 'transactions'))
|
Block = namedtuple('Block', ('app_hash', 'height', 'transactions'))
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
from flask import current_app
|
from flask import current_app
|
||||||
from flask_restful import Resource
|
from flask_restful import Resource
|
||||||
|
|
||||||
from bigchaindb.web.views.base import make_error
|
|
||||||
|
|
||||||
|
|
||||||
class ValidatorsApi(Resource):
|
class ValidatorsApi(Resource):
|
||||||
def get(self):
|
def get(self):
|
||||||
@ -14,11 +12,7 @@ class ValidatorsApi(Resource):
|
|||||||
|
|
||||||
pool = current_app.config['bigchain_pool']
|
pool = current_app.config['bigchain_pool']
|
||||||
|
|
||||||
try:
|
with pool() as bigchain:
|
||||||
with pool() as bigchain:
|
validators = bigchain.get_validators()
|
||||||
validators = bigchain.get_validators()
|
|
||||||
|
|
||||||
return validators
|
return validators
|
||||||
|
|
||||||
except Exception:
|
|
||||||
return make_error(500)
|
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
from requests.exceptions import RequestException
|
||||||
|
|
||||||
pytestmark = pytest.mark.tendermint
|
pytestmark = pytest.mark.tendermint
|
||||||
|
|
||||||
VALIDATORS_ENDPOINT = '/api/v1/validators/'
|
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 test_get_validators_500_endpoint(b, client, monkeypatch):
|
||||||
|
|
||||||
def mock_get(uri):
|
def mock_get(uri):
|
||||||
return 'InvalidResponse'
|
raise RequestException
|
||||||
monkeypatch.setattr('requests.get', mock_get)
|
monkeypatch.setattr('requests.get', mock_get)
|
||||||
|
|
||||||
res = client.get(VALIDATORS_ENDPOINT)
|
with pytest.raises(RequestException):
|
||||||
assert res.status_code == 500
|
client.get(VALIDATORS_ENDPOINT)
|
||||||
|
|
||||||
|
|
||||||
# Helper
|
# Helper
|
||||||
|
Loading…
x
Reference in New Issue
Block a user