Skip to content

Commit 0d41383

Browse files
author
abel
committed
(fix) Added exception handling to prevent connection issues from braking the AsyncClient initialization when getting the official tokens list from GitHub
1 parent f59766b commit 0d41383

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

pyinjective/core/tokens_file_loader.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import aiohttp
44

55
from pyinjective.core.token import Token
6+
from pyinjective.utils.logger import LoggerProvider
67

78

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

2728
async def load_tokens(self, tokens_file_url: str) -> List[Token]:
2829
tokens_list = []
29-
async with aiohttp.ClientSession() as session:
30-
async with session.get(tokens_file_url) as response:
31-
if response.ok:
32-
tokens_list = await response.json(content_type=None)
30+
try:
31+
async with aiohttp.ClientSession() as session:
32+
async with session.get(tokens_file_url) as response:
33+
if response.ok:
34+
tokens_list = await response.json(content_type=None)
35+
except Exception as e:
36+
LoggerProvider().logger_for_class(logging_class=self.__class__).warning(
37+
f"there was an error fetching the list of official tokens: {e}"
38+
)
3339

3440
return self.load_json(tokens_list)

0 commit comments

Comments
 (0)