Skip to content

Commit aed5652

Browse files
committed
Undo JSCPD fix
1 parent 71d8dd4 commit aed5652

File tree

1 file changed

+30
-45
lines changed

1 file changed

+30
-45
lines changed

src/a2a/client/client.py

Lines changed: 30 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -26,36 +26,6 @@
2626
)
2727

2828

29-
async def _make_httpx_request(
30-
client: httpx.AsyncClient,
31-
method: str,
32-
url: str,
33-
json_payload: dict[str, Any] | None = None,
34-
http_kwargs: dict[str, Any] | None = None,
35-
) -> dict[str, Any]:
36-
"""Makes an HTTP request and handles common errors, returning parsed JSON."""
37-
try:
38-
if method.upper() == 'GET':
39-
response = await client.get(url, **(http_kwargs or {}))
40-
elif method.upper() == 'POST':
41-
response = await client.post(
42-
url, json=json_payload, **(http_kwargs or {})
43-
)
44-
else:
45-
raise ValueError(f'Unsupported HTTP method: {method}')
46-
47-
response.raise_for_status()
48-
return response.json()
49-
except httpx.HTTPStatusError as e:
50-
raise A2AClientHTTPError(e.response.status_code, str(e)) from e
51-
except json.JSONDecodeError as e:
52-
raise A2AClientJSONError(str(e)) from e
53-
except httpx.RequestError as e:
54-
raise A2AClientHTTPError(
55-
503, f'Network communication error: {e}'
56-
) from e
57-
58-
5929
class A2ACardResolver:
6030
"""Agent Card resolver."""
6131

@@ -72,13 +42,21 @@ def __init__(
7242
async def get_agent_card(
7343
self, http_kwargs: dict[str, Any] | None = None
7444
) -> AgentCard:
75-
response_json = await _make_httpx_request(
76-
client=self.httpx_client,
77-
method='GET',
78-
url=f'{self.base_url}/{self.agent_card_path}',
79-
http_kwargs=http_kwargs,
80-
)
81-
return AgentCard.model_validate(response_json)
45+
try:
46+
response = await self.httpx_client.get(
47+
f'{self.base_url}/{self.agent_card_path}',
48+
**(http_kwargs or {}),
49+
)
50+
response.raise_for_status()
51+
return AgentCard.model_validate(response.json())
52+
except httpx.HTTPStatusError as e:
53+
raise A2AClientHTTPError(e.response.status_code, str(e)) from e
54+
except json.JSONDecodeError as e:
55+
raise A2AClientJSONError(str(e)) from e
56+
except httpx.RequestError as e:
57+
raise A2AClientHTTPError(
58+
503, f'Network communication error: {e}'
59+
) from e
8260

8361

8462
class A2AClient:
@@ -174,15 +152,22 @@ async def _send_request(
174152
175153
Args:
176154
rpc_request_payload: JSON RPC payload for sending the request
177-
http_kwargs: Additional keyword arguments to pass to the httpx client.
155+
**kwargs: Additional keyword arguments to pass to the httpx client.
178156
"""
179-
return await _make_httpx_request(
180-
client=self.httpx_client,
181-
method='POST',
182-
url=self.url,
183-
json_payload=rpc_request_payload,
184-
http_kwargs=http_kwargs,
185-
)
157+
try:
158+
response = await self.httpx_client.post(
159+
self.url, json=rpc_request_payload, **(http_kwargs or {})
160+
)
161+
response.raise_for_status()
162+
return response.json()
163+
except httpx.HTTPStatusError as e:
164+
raise A2AClientHTTPError(e.response.status_code, str(e)) from e
165+
except json.JSONDecodeError as e:
166+
raise A2AClientJSONError(str(e)) from e
167+
except httpx.RequestError as e:
168+
raise A2AClientHTTPError(
169+
503, f'Network communication error: {e}'
170+
) from e
186171

187172
async def get_task(
188173
self,

0 commit comments

Comments
 (0)