From 0c1aa9f8778c3505d4dc5b9088c3b20659de1203 Mon Sep 17 00:00:00 2001 From: "Max \"Maxitosh\" Kureikin" Date: Sat, 2 Nov 2024 18:57:42 +0400 Subject: [PATCH 1/2] Add lib-specific exceptions --- pytonlib/client.py | 3 ++- pytonlib/exceptions.py | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 pytonlib/exceptions.py diff --git a/pytonlib/client.py b/pytonlib/client.py index 3a5b93a..3486817 100644 --- a/pytonlib/client.py +++ b/pytonlib/client.py @@ -5,6 +5,7 @@ import logging import os +from pytonlib.exceptions import SmartContractIsNotJettonOrNft 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 SmartContractIsNotJettonOrNft() result = None if contract_type == 'jetton_master': diff --git a/pytonlib/exceptions.py b/pytonlib/exceptions.py new file mode 100644 index 0000000..fe406c5 --- /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 SmartContractIsNotJettonOrNft(PyTonLibException): + """Raised when the smart contract is not a Jetton or NFT.""" + + message = "Smart contract is not a Jetton or NFT" From edf66cf1476c3af5920bc45b99cc45a2df72919f Mon Sep 17 00:00:00 2001 From: "Max \"Maxitosh\" Kureikin" Date: Sat, 2 Nov 2024 22:01:47 +0400 Subject: [PATCH 2/2] Add Exception suffix to SmartContractIsNotJettonOrNft --- pytonlib/client.py | 4 ++-- pytonlib/exceptions.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pytonlib/client.py b/pytonlib/client.py index 3486817..9d1b6f2 100644 --- a/pytonlib/client.py +++ b/pytonlib/client.py @@ -5,7 +5,7 @@ import logging import os -from pytonlib.exceptions import SmartContractIsNotJettonOrNft +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 @@ -873,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 SmartContractIsNotJettonOrNft() + raise SmartContractIsNotJettonOrNftException() result = None if contract_type == 'jetton_master': diff --git a/pytonlib/exceptions.py b/pytonlib/exceptions.py index fe406c5..56746fc 100644 --- a/pytonlib/exceptions.py +++ b/pytonlib/exceptions.py @@ -10,7 +10,7 @@ def __init__(self, message: Optional[str] = None): super().__init__(message or self.message) -class SmartContractIsNotJettonOrNft(PyTonLibException): +class SmartContractIsNotJettonOrNftException(PyTonLibException): """Raised when the smart contract is not a Jetton or NFT.""" message = "Smart contract is not a Jetton or NFT"