1+ import asyncio
12import functools
23import logging
34from collections .abc import Callable
45from dataclasses import dataclass , field
56from typing import Any , TypeVar
67
7- import orjson
8- from models_library .utils .fastapi_encoders import jsonable_encoder
98from pydantic import SecretStr
109
11- from ..logging_utils import log_catch , log_context
10+ from ..logging_utils import log_context
11+ from ._errors import RPCServerError
1212from ._models import RPCMethodName
1313
1414DecoratedCallable = TypeVar ("DecoratedCallable" , bound = Callable [..., Any ])
@@ -32,14 +32,18 @@ async def wrapper(*args, **kwargs):
3232 _logger ,
3333 logging .INFO ,
3434 msg = f"calling { func .__name__ } with { args } , { kwargs } " ,
35- ), log_catch (_logger , reraise = True ):
36- result = await func (* args , ** kwargs )
37- return orjson .dumps (
38- jsonable_encoder (
39- result ,
40- custom_encoder = _RPC_CUSTOM_ENCODER ,
41- )
42- )
35+ ):
36+ try :
37+ result = await func (* args , ** kwargs )
38+ return result
39+ except asyncio .CancelledError :
40+ _logger .debug ("call was cancelled" )
41+ raise
42+ except Exception as exc : # pylint: disable=broad-except
43+ _logger .exception ("Unhandled exception:" )
44+ raise RPCServerError (
45+ method_name = func .__name__ , exc_type = type (exc ), msg = f"{ exc } "
46+ ) from exc
4347
4448 self .routes [RPCMethodName (func .__name__ )] = wrapper
4549 return func
0 commit comments