Skip to content

Commit

Permalink
Merge pull request man-c#25 from cryptocmd-com/fix/unbound_local
Browse files Browse the repository at this point in the history
Fix unbound local exception on GET request failure
  • Loading branch information
man-c authored Jan 4, 2021
2 parents 87e6ec2 + e4d0698 commit 74df2a2
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 74df2a2

Please sign in to comment.