@@ -53,6 +53,7 @@ def _map_grpc_error(e: grpc.aio.AioRpcError) -> NoReturn:
5353 details = e .details ()
5454 if isinstance (details , str ) and ': ' in details :
5555 error_type_name , error_message = details .split (': ' , 1 )
56+ # TODO(#723): Resolving imports by name is a temporary hack until proper error handling structure is added in #723.
5657 exception_cls = getattr (a2a .utils .errors , error_type_name , None )
5758 if (
5859 exception_cls
@@ -62,23 +63,29 @@ def _map_grpc_error(e: grpc.aio.AioRpcError) -> NoReturn:
6263 raise exception_cls (error_message ) from e
6364 raise A2AClientError (f'gRPC Error { e .code ().name } : { e .details ()} ' ) from e
6465
66+
6567def _handle_grpc_exception (func : Callable [..., Any ]) -> Callable [..., Any ]:
6668 @wraps (func )
6769 async def wrapper (* args : Any , ** kwargs : Any ) -> Any :
6870 try :
6971 return await func (* args , ** kwargs )
7072 except grpc .aio .AioRpcError as e :
7173 _map_grpc_error (e )
74+
7275 return wrapper
7376
74- def _handle_grpc_stream_exception (func : Callable [..., Any ]) -> Callable [..., Any ]:
77+
78+ def _handle_grpc_stream_exception (
79+ func : Callable [..., Any ],
80+ ) -> Callable [..., Any ]:
7581 @wraps (func )
7682 async def wrapper (* args : Any , ** kwargs : Any ) -> Any :
7783 try :
7884 async for item in func (* args , ** kwargs ):
7985 yield item
8086 except grpc .aio .AioRpcError as e :
8187 _map_grpc_error (e )
88+
8289 return wrapper
8390
8491
0 commit comments