Skip to content

Commit eada908

Browse files
Fixed return code for non-token smc in getTokenData method
1 parent c5b4a4b commit eada908

2 files changed

Lines changed: 13 additions & 8 deletions

File tree

ton-http-api/.docker/Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
FROM ubuntu:22.04
1+
FROM ubuntu:24.04
22

33
RUN DEBIAN_FRONTEND=noninteractive TZ=Etc/UTC apt-get update && apt-get -y install tzdata
44
RUN apt-get update -y && apt-get install -y wget python3 python3-pip zlib1g-dev libsecp256k1-dev \
55
libmicrohttpd-dev libsodium-dev liblz4-dev libjemalloc-dev && rm -rf /var/lib/{apt,dpkg,cache,log}/
66

77
# python requirements
88
ADD ./requirements.txt /tmp/requirements.txt
9-
RUN python3 -m pip install --no-cache-dir -r /tmp/requirements.txt
9+
RUN python3 -m pip install --no-cache-dir --break-system-packages -r /tmp/requirements.txt
1010

1111
# app
1212
COPY . /app

ton-http-api/pyTON/main.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
from pytonlib.utils.address import detect_address as __detect_address, prepare_address as _prepare_address
3131
from pytonlib.utils.wallet import wallets as known_wallets, sha256
3232
from pytonlib.utils.common import hash_to_hex, hex_to_b64str
33-
from pytonlib import TonlibException
33+
from pytonlib import TonlibException, TonlibError
3434

3535
from loguru import logger
3636

@@ -168,10 +168,12 @@ async def timeout_exception_handler(request, exc):
168168

169169

170170
@app.exception_handler(TonlibException)
171-
async def tonlib_error_result_exception_handler(request, exc):
172-
res = TonResponse(ok=False, error=str(exc), code=status.HTTP_500_INTERNAL_SERVER_ERROR)
173-
return JSONResponse(res.dict(exclude_none=True), status_code=status.HTTP_500_INTERNAL_SERVER_ERROR)
174-
171+
async def tonlib_exception_result_exception_handler(request, exc):
172+
status_code = status.HTTP_500_INTERNAL_SERVER_ERROR
173+
if str(exc) == 'Smart contract is not Jetton or NFT':
174+
status_code = 409
175+
res = TonResponse(ok=False, error=str(exc), code=status_code)
176+
return JSONResponse(res.dict(exclude_none=True), status_code=status_code)
175177

176178
@app.exception_handler(Exception)
177179
async def fastapi_generic_exception_handler(request, exc):
@@ -555,7 +557,10 @@ async def get_token_data(
555557
Get NFT or Jetton information.
556558
"""
557559
address = prepare_address(address)
558-
return await tonlib.get_token_data(address)
560+
try:
561+
return await tonlib.get_token_data(address)
562+
except Exception as exc:
563+
raise TonlibException(exc)
559564

560565
@app.get('/tryLocateTx', response_model=TonResponse, response_model_exclude_none=True, tags=['transactions'])
561566
@json_rpc('tryLocateTx')

0 commit comments

Comments
 (0)