Skip to content

Commit

Permalink
Fix unbound local exception on GET request failure
Browse files Browse the repository at this point in the history
  • Loading branch information
yitzikc committed Dec 21, 2020
1 parent 8b7a845 commit e4d0698
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
7 changes: 5 additions & 2 deletions pycoingecko/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ def __request(self, url):
# print(url)
try:
response = self.session.get(url, timeout=self.request_timeout)
except requests.exceptions.RequestException:
raise

try:
response.raise_for_status()
content = json.loads(response.content.decode('utf-8'))
return content
Expand All @@ -33,8 +37,7 @@ def __request(self, url):
# if no json
except json.decoder.JSONDecodeError:
pass
# except UnboundLocalError as e:
# pass

raise

def __api_url_params(self, api_url, params):
Expand Down
7 changes: 7 additions & 0 deletions tests/test_api.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
import pytest
import requests.exceptions
import responses
import unittest
import unittest.mock as mock

from pycoingecko import CoinGeckoAPI
from requests.exceptions import HTTPError


class TestWrapper(unittest.TestCase):

@responses.activate
def test_connection_error(self):
with pytest.raises(requests.exceptions.ConnectionError):
CoinGeckoAPI().ping()

@responses.activate
def test_failed_ping(self):
# Arrange
Expand Down

0 comments on commit e4d0698

Please sign in to comment.