Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Custom Library-Specific Exceptions #68

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion pytonlib/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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':
Expand Down
16 changes: 16 additions & 0 deletions pytonlib/exceptions.py
Original file line number Diff line number Diff line change
@@ -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"