diff --git a/app/core/_blockchain/ton/toncenter.py b/app/core/_blockchain/ton/toncenter.py index 2949ade..a3eed4c 100644 --- a/app/core/_blockchain/ton/toncenter.py +++ b/app/core/_blockchain/ton/toncenter.py @@ -14,7 +14,10 @@ class TonCenter: self.api_key = api_key self.last_used = time.time() - async def request(self, method: str, endpoint: str, *args, **kwargs) -> dict: + async def request(self, method: str, endpoint: str, *args, tries_count=0, **kwargs) -> dict: + if tries_count > 3: + raise Exception(f'Error while toncenter request {endpoint}: {tries_count}') + async with AsyncClient(headers={ 'Authorization': f"Bearer {self.api_key}" } if self.api_key else None) as client: @@ -35,7 +38,7 @@ class TonCenter: return response.json() except BaseException as e: make_log("Toncenter", f'Error while request {self.host}{endpoint}: {e}' + '\n' + response.text, level='error') - return await self.request(method, endpoint, *args, **kwargs) + return await self.request(method, endpoint, *args, tries_count=(tries_count + 1), **kwargs) async def send_boc(self, src: bytes): try: