Skip to content

Commit

Permalink
(fix) Added exception handling to prevent connection issues from brak…
Browse files Browse the repository at this point in the history
…ing the AsyncClient initialization when getting the official tokens list from GitHub
  • Loading branch information
abel committed May 7, 2024
1 parent f59766b commit 0d41383
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions pyinjective/core/tokens_file_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import aiohttp

from pyinjective.core.token import Token
from pyinjective.utils.logger import LoggerProvider


class TokensFileLoader:
Expand All @@ -26,9 +27,14 @@ def load_json(self, json: List[Dict]) -> List[Token]:

async def load_tokens(self, tokens_file_url: str) -> List[Token]:
tokens_list = []
async with aiohttp.ClientSession() as session:
async with session.get(tokens_file_url) as response:
if response.ok:
tokens_list = await response.json(content_type=None)
try:
async with aiohttp.ClientSession() as session:
async with session.get(tokens_file_url) as response:
if response.ok:
tokens_list = await response.json(content_type=None)
except Exception as e:
LoggerProvider().logger_for_class(logging_class=self.__class__).warning(
f"there was an error fetching the list of official tokens: {e}"
)

return self.load_json(tokens_list)

0 comments on commit 0d41383

Please sign in to comment.