Skip to content

Commit ec2248a

Browse files
committed
AgentCardResolutionError updates
1 parent 3e32834 commit ec2248a

3 files changed

Lines changed: 7 additions & 2 deletions

File tree

src/a2a/client/card_resolver.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,15 @@ async def get_agent_card(
9191
except httpx.HTTPStatusError as e:
9292
raise AgentCardResolutionError(
9393
f'Failed to fetch agent card from {target_url} (HTTP {e.response.status_code}): {e}',
94+
status_code=e.response.status_code,
9495
) from e
9596
except json.JSONDecodeError as e:
9697
raise AgentCardResolutionError(
9798
f'Failed to parse JSON for agent card from {target_url}: {e}'
9899
) from e
99100
except httpx.RequestError as e:
100101
raise AgentCardResolutionError(
101-
f'Network communication error fetching agent card from {target_url} (HTTP 503): {e}',
102+
f'Network communication error fetching agent card from {target_url}: {e}',
102103
) from e
103104
except ParseError as e:
104105
raise AgentCardResolutionError(

src/a2a/client/errors.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,7 @@ class A2AClientError(A2AError):
99

1010
class AgentCardResolutionError(A2AClientError):
1111
"""Exception raised when an agent card cannot be resolved."""
12+
13+
def __init__(self, message: str, status_code: int | None = None) -> None:
14+
super().__init__(message)
15+
self.status_code = status_code

tests/client/test_card_resolver.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ async def test_get_agent_card_http_status_error(
221221
with pytest.raises(AgentCardResolutionError) as exc_info:
222222
await resolver.get_agent_card()
223223

224+
assert exc_info.value.status_code == status_code
224225
assert f'HTTP {status_code}' in str(exc_info.value)
225226
assert 'Failed to fetch agent card' in str(exc_info.value)
226227

@@ -247,7 +248,6 @@ async def test_get_agent_card_request_error(
247248
)
248249
with pytest.raises(AgentCardResolutionError) as exc_info:
249250
await resolver.get_agent_card()
250-
assert 'HTTP 503' in str(exc_info.value)
251251
assert 'Network communication error' in str(exc_info.value)
252252

253253
@pytest.mark.asyncio

0 commit comments

Comments
 (0)