[Bug]: JSON-RPC client ignores the JSON-RPC error body when the HTTP status is not 2xx
维护者通常 2 天内回复
评估
这个 Issue 还没有评估数据。
描述
What happened?
JsonRpcTransport raises the mapped A2A error for a JSON-RPC error response only when the HTTP status is 2xx. If a server sends the same error body with a non-2xx status, the client raises a generic A2AClientError("HTTP Error 500: ..."). The JSON-RPC error code and the server's message are lost.
a2a-js does this. Errors raised outside its main handler (the user builder, the agent card lookup) that map to -32603 are sent as HTTP 500 with a normal JSON-RPC error body (json_rpc_handler.ts#L219-L220). Section 9.5 of the spec defines the error object, not the HTTP status, so the client can't assume 200. RestTransport already reads the error body on non-2xx responses (_handle_http_error).
To reproduce on main (caab6a2):
import asyncio
import httpx
from a2a.client.transports.jsonrpc import JsonRpcTransport
from a2a.types.a2a_pb2 import AgentCard, GetTaskRequest
BODY = {
'jsonrpc': '2.0',
'id': '1',
'error': {'code': -32603, 'message': 'database connection lost'},
}
async def main(status: int) -> None:
client = httpx.AsyncClient(
transport=httpx.MockTransport(
lambda request: httpx.Response(status, json=BODY)
)
)
transport = JsonRpcTransport(client, AgentCard(), 'http://agent')
try:
await transport.get_task(GetTaskRequest(id='t1'))
except Exception as e:
print(f'HTTP {status}: {type(e).__name__}: {e}')
asyncio.run(main(200))
asyncio.run(main(500))
Expected: both calls raise InternalError: database connection lost.
Actual: the HTTP 500 call raises A2AClientError: HTTP Error 500: .... send_message_streaming and subscribe behave the same way: a 404 whose body is a -32001 error raises A2AClientError instead of TaskNotFoundError.
Root cause: _send_request and _send_stream_request pass no status_error_handler to the shared HTTP helpers (jsonrpc.py#L319-L330, jsonrpc.py#L368-L376), so handle_http_exceptions raises without reading the body.
Proposed fix: give JsonRpcTransport a status error handler, like RestTransport._handle_http_error. If the body is a JSON-RPC error object, raise the mapped error. Otherwise keep the current A2AClientError("HTTP Error ..."), so HTML pages from proxies and other non-JSON-RPC bodies behave as today.
One behaviour change to flag: code that catches A2AClientError for these responses would get the mapped A2AError subclass instead (InternalError is not an A2AClientError). That's already what happens for the same body at HTTP 200, and what RestTransport does. except A2AError is unaffected.
I'm happy to open a PR for this.
Relevant log output
HTTP 200: InternalError: database connection lost
HTTP 500: A2AClientError: HTTP Error 500: Server error '500 Internal Server Error' for url 'http://agent'
For more information check: https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/500
- 主要语言
- Python
- 星标
- 2.2k
- 派生
- 540
- 平均合并
- 2 天 9 小时
- 30 天内合并 PR
- 56
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
a2aproject/a2a-python 的其他 Issue
-
[Bug]: `A2A-Version` validation ignores minor versions and the query parameter可能已有人在做 @rohityan 于 82 天前认领。 未关闭component: server status:awaiting response status:stale
难度 2/5 1-3 小时 新手友好度 75/100
a2aproject/a2a-python#1204 · 4 条评论 · 已指派 1 人 ·
维护者通常 2 天内回复
-
[Bug]: REST task/request id sanitization可能重新可做 关联的 PR 已关闭且未合并。 未关闭maintainers-only
难度 2/5 1-3 小时 新手友好度 65/100
a2aproject/a2a-python#805 · 1 条评论 ·
维护者通常 2 天内回复
-
[Feat]: validate_input_modes: match media ranges such as image/* declared in the agent card可能已有人在做 @rohityan 于 2 天前认领。 未关闭
a2aproject/a2a-python#1468 · 已指派 2 人 ·
维护者通常 2 天内回复
-
Required extensions aren't enforced, so ExtensionSupportRequiredError is never raised可能已有人在做 @rohityan 于 2 天前认领。 未关闭component: server status:awaiting response
a2aproject/a2a-python#1467 · 1 条评论 · 已指派 1 人 ·
维护者通常 2 天内回复
-
[Bug]: ListTasks prints unset fields on every task (history: [] with historyLength=0, empty mediaType/filename on parts)可能已有人在做 @rohityan 于 3 天前认领。 未关闭
a2aproject/a2a-python#1461 · 已指派 1 人 ·
维护者通常 2 天内回复
查看 a2aproject/a2a-python 的全部 Issue
相似的 Issue
-
area:security effort:S priority:P3 status:needs-triage type:chore
难度 2/5 1-3 小时 新手友好度 78/100
randomparity/kdive#3657 ·
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 78/100
aws/mcp-proxy-for-aws#476 ·
维护者通常 1 天内回复
-
fix(cli): a --root that does not exist exits 0 with 'Scanned 0 file(s)', so a wrong path in CI passes silently可能已有人在做 @arpanjot-coding 今天认领。 未关闭area: runtime automation bug cli code-scanning consistency developer-experience difficulty: easy github-actions good first issue help wanted json-output priority: P3 python sarif silent-failure static-analysis tests
难度 2/5 1-3 小时 新手友好度 82/100
-
ContainsOnly raises TypeError for unhashable input with set-based choices可能已有人在做 @prathamchoksi 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 84/100
marshmallow-code/marshmallow#3115 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 76/100
维护者通常 1 天内回复