with logging

This commit is contained in:
2024-10-08 14:12:04 +03:00
parent e7d98d1b64
commit 1baec8454e

View File

@ -1,4 +1,5 @@
import contextlib import contextlib
import logging
from pathlib import Path from pathlib import Path
from typing import Self from typing import Self
@ -120,11 +121,13 @@ class BaseThon(BaseData):
json_data: dict, json_data: dict,
retries: int = 50, retries: int = 50,
timeout: int = 10, timeout: int = 10,
debug: bool = False,
raise_error: bool = True, raise_error: bool = True,
): ):
self.__item, self.__retries, self.__timeout = item, retries, timeout self.__item, self.__retries, self.__timeout = item, retries, timeout
super().__init__(json_data, raise_error) super().__init__(json_data, raise_error)
self.__client = self.__get_client() self.__client = self.__get_client()
self.__debug = debug
@property @property
def client(self) -> TelegramClient: def client(self) -> TelegramClient:
@ -160,6 +163,8 @@ class BaseThon(BaseData):
return "ERROR_AUTH:BAN_ERROR" return "ERROR_AUTH:BAN_ERROR"
except Exception as e: except Exception as e:
await self.disconnect() await self.disconnect()
if self.__debug:
logging.exception(e)
return f"ERROR_AUTH:{e}" return f"ERROR_AUTH:{e}"
async def disconnect(self): async def disconnect(self):