File tree Expand file tree Collapse file tree 4 files changed +45
-1
lines changed Expand file tree Collapse file tree 4 files changed +45
-1
lines changed Original file line number Diff line number Diff line change 10
10
A2AClientError ,
11
11
A2AClientHTTPError ,
12
12
A2AClientJSONError ,
13
+ A2AClientTimeoutError ,
13
14
)
14
15
from a2a .client .grpc_client import A2AGrpcClient
15
16
from a2a .client .helpers import create_text_message_object
22
23
'A2AClientError' ,
23
24
'A2AClientHTTPError' ,
24
25
'A2AClientJSONError' ,
26
+ 'A2AClientTimeoutError' ,
25
27
'A2AGrpcClient' ,
26
28
'AuthInterceptor' ,
27
29
'ClientCallContext' ,
Original file line number Diff line number Diff line change 10
10
from httpx_sse import SSEError , aconnect_sse
11
11
from pydantic import ValidationError
12
12
13
- from a2a .client .errors import A2AClientHTTPError , A2AClientJSONError
13
+ from a2a .client .errors import (
14
+ A2AClientHTTPError ,
15
+ A2AClientJSONError ,
16
+ A2AClientTimeoutError ,
17
+ )
14
18
from a2a .client .middleware import ClientCallContext , ClientCallInterceptor
15
19
from a2a .types import (
16
20
AgentCard ,
@@ -340,6 +344,8 @@ async def _send_request(
340
344
)
341
345
response .raise_for_status ()
342
346
return response .json ()
347
+ except httpx .ReadTimeout as e :
348
+ raise A2AClientTimeoutError ('Client Request timed out' ) from e
343
349
except httpx .HTTPStatusError as e :
344
350
raise A2AClientHTTPError (e .response .status_code , str (e )) from e
345
351
except json .JSONDecodeError as e :
Original file line number Diff line number Diff line change @@ -31,3 +31,16 @@ def __init__(self, message: str):
31
31
"""
32
32
self .message = message
33
33
super ().__init__ (f'JSON Error: { message } ' )
34
+
35
+
36
+ class A2AClientTimeoutError (A2AClientError ):
37
+ """Client exception for timeout errors during a request."""
38
+
39
+ def __init__ (self , message : str ):
40
+ """Initializes the A2AClientTimeoutError.
41
+
42
+ Args:
43
+ message: A descriptive error message.
44
+ """
45
+ self .message = message
46
+ super ().__init__ (f'Timeout Error: { message } ' )
Original file line number Diff line number Diff line change 14
14
A2AClient ,
15
15
A2AClientHTTPError ,
16
16
A2AClientJSONError ,
17
+ A2AClientTimeoutError ,
17
18
create_text_message_object ,
18
19
)
19
20
from a2a .types import (
@@ -1266,3 +1267,25 @@ async def test_cancel_task_error_response(
1266
1267
mode = 'json' , exclude_none = True
1267
1268
) == error_details .model_dump (exclude_none = True )
1268
1269
assert response .root .id == 'err_cancel_req'
1270
+
1271
+ @pytest .mark .asyncio
1272
+ async def test_send_message_client_timeout (
1273
+ self , mock_httpx_client : AsyncMock , mock_agent_card : MagicMock
1274
+ ):
1275
+ mock_httpx_client .post .side_effect = httpx .ReadTimeout (
1276
+ 'Request timed out'
1277
+ )
1278
+ client = A2AClient (
1279
+ httpx_client = mock_httpx_client , agent_card = mock_agent_card
1280
+ )
1281
+
1282
+ params = MessageSendParams (
1283
+ message = create_text_message_object (content = 'Hello' )
1284
+ )
1285
+
1286
+ request = SendMessageRequest (id = 123 , params = params )
1287
+
1288
+ with pytest .raises (A2AClientTimeoutError ) as exc_info :
1289
+ await client .send_message (request = request )
1290
+
1291
+ assert 'Request timed out' in str (exc_info .value )
You can’t perform that action at this time.
0 commit comments