You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(rest): update REST error handling to use google.rpc.Status (#838)
# Description
This PR refactors the REST transport error handling to adhere to the
`google.rpc.Status` JSON format. Both the server-side exception handlers
and the client-side REST transport have been updated to utilize the new
standard error envelope, ensuring consistency across A2A REST APIs.
## Summary of Changes
* **Server:**
* Updated `rest_error_handler` and the global `StarletteHTTPException`
handler in `A2ARESTFastAPIApplication` to return errors wrapped in an
`{'error': {...}}` envelope.
* Payloads now correctly include the HTTP `code`, gRPC `status`,
`message`, and a `details` array containing
`type.googleapis.com/google.rpc.ErrorInfo` for the specific reason and
metadata.
* **Client:**
* Modified `RestTransport._handle_http_error` to parse the new format.
It now gracefully extracts the `reason` from the `ErrorInfo` detail
object to map it back to the corresponding Python `A2AError` class.
* **Core/Utils:**
* Introduced `A2A_REST_ERROR_MAPPING` in `errors.py` to centralize the
mapping of Python exceptions to their respective HTTP status codes, gRPC
statuses, and string reasons.
* Added a `data` attribute to the base `A2AError` to carry arbitrary
error metadata.
* **Tests:**
* Updated REST client, server, and error handler tests to validate the
new nested `{'error': {...}}` JSON payload structures.
- [X] Follow the [`CONTRIBUTING`
Guide](https://github.com/a2aproject/a2a-python/blob/main/CONTRIBUTING.md).
- [X] Make your Pull Request title in the
<https://www.conventionalcommits.org/> specification.
- Important Prefixes for
[release-please](https://github.com/googleapis/release-please):
- `fix:` which represents bug fixes, and correlates to a
[SemVer](https://semver.org/) patch.
- `feat:` represents a new feature, and correlates to a SemVer minor.
- `feat!:`, or `fix!:`, `refactor!:`, etc., which represent a breaking
change (indicated by the `!`) and will result in a SemVer major.
- [X] Ensure the tests and linter pass (Run `bash scripts/format.sh`
from the repository root to format)
- [X] Appropriate docs were updated (if necessary)
Fixes#722 🦕
---------
Co-authored-by: Ivan Shymko <ishymko@google.com>
0 commit comments