diff --git a/pytonlib/client.py b/pytonlib/client.py index 3a5b93a..9d1b6f2 100644 --- a/pytonlib/client.py +++ b/pytonlib/client.py @@ -5,6 +5,7 @@ import logging import os +from pytonlib.exceptions import SmartContractIsNotJettonOrNftException from pytonlib.tonlibjson import TonLib from pytonlib.utils.address import prepare_address, detect_address from pytonlib.utils.common import b64str_to_hex, hex_to_b64str, hash_to_hex @@ -872,7 +873,7 @@ async def get_token_data(self, address: str, skip_verification=False): get_method_result_stack = get_method_results[i]['stack'] if contract_type is None or get_method_result_stack is None: - raise Exception("Smart contract is not Jetton or NFT") + raise SmartContractIsNotJettonOrNftException() result = None if contract_type == 'jetton_master': diff --git a/pytonlib/exceptions.py b/pytonlib/exceptions.py new file mode 100644 index 0000000..56746fc --- /dev/null +++ b/pytonlib/exceptions.py @@ -0,0 +1,16 @@ +from typing import Optional + + +class PyTonLibException(Exception): + """Base class for exceptions in the PyTONLib library.""" + + message = "An error occurred in the PyTONLib library" + + def __init__(self, message: Optional[str] = None): + super().__init__(message or self.message) + + +class SmartContractIsNotJettonOrNftException(PyTonLibException): + """Raised when the smart contract is not a Jetton or NFT.""" + + message = "Smart contract is not a Jetton or NFT"