|
30 | 30 | from pytonlib.utils.address import detect_address as __detect_address, prepare_address as _prepare_address |
31 | 31 | from pytonlib.utils.wallet import wallets as known_wallets, sha256 |
32 | 32 | from pytonlib.utils.common import hash_to_hex, hex_to_b64str |
33 | | -from pytonlib import TonlibException |
| 33 | +from pytonlib import TonlibException, TonlibError |
34 | 34 |
|
35 | 35 | from loguru import logger |
36 | 36 |
|
@@ -168,10 +168,12 @@ async def timeout_exception_handler(request, exc): |
168 | 168 |
|
169 | 169 |
|
170 | 170 | @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) |
175 | 177 |
|
176 | 178 | @app.exception_handler(Exception) |
177 | 179 | async def fastapi_generic_exception_handler(request, exc): |
@@ -555,7 +557,10 @@ async def get_token_data( |
555 | 557 | Get NFT or Jetton information. |
556 | 558 | """ |
557 | 559 | 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) |
559 | 564 |
|
560 | 565 | @app.get('/tryLocateTx', response_model=TonResponse, response_model_exclude_none=True, tags=['transactions']) |
561 | 566 | @json_rpc('tryLocateTx') |
|
0 commit comments