Commit ea7d3ad
feat(rest): update REST error handling to use
# 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>google.rpc.Status (#838)1 parent cac6f58 commit ea7d3ad
File tree
8 files changed
+265
-114
lines changed- .github/actions/spelling
- src/a2a
- client/transports
- server/apps/rest
- utils
- tests
- client/transports
- server/apps/rest
- utils
8 files changed
+265
-114
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| 17 | + | |
17 | 18 | | |
18 | 19 | | |
19 | 20 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
37 | | - | |
| 37 | + | |
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | | - | |
47 | 43 | | |
48 | 44 | | |
49 | 45 | | |
| |||
297 | 293 | | |
298 | 294 | | |
299 | 295 | | |
300 | | - | |
301 | | - | |
302 | | - | |
| 296 | + | |
| 297 | + | |
303 | 298 | | |
304 | | - | |
305 | | - | |
306 | | - | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
307 | 321 | | |
308 | | - | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
309 | 326 | | |
310 | 327 | | |
311 | 328 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
10 | 11 | | |
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
14 | 15 | | |
15 | 16 | | |
| 17 | + | |
16 | 18 | | |
17 | 19 | | |
18 | 20 | | |
19 | 21 | | |
20 | 22 | | |
21 | 23 | | |
22 | 24 | | |
| 25 | + | |
23 | 26 | | |
24 | 27 | | |
25 | 28 | | |
| |||
36 | 39 | | |
37 | 40 | | |
38 | 41 | | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
39 | 59 | | |
40 | 60 | | |
41 | 61 | | |
| |||
121 | 141 | | |
122 | 142 | | |
123 | 143 | | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
124 | 172 | | |
125 | 173 | | |
126 | 174 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
| 5 | + | |
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
20 | | - | |
21 | | - | |
22 | | - | |
23 | | - | |
24 | | - | |
25 | | - | |
26 | | - | |
27 | 20 | | |
| 21 | + | |
28 | 22 | | |
29 | | - | |
30 | | - | |
31 | | - | |
32 | 23 | | |
33 | | - | |
34 | | - | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | | - | |
41 | | - | |
| 24 | + | |
42 | 25 | | |
43 | 26 | | |
44 | 27 | | |
45 | 28 | | |
46 | 29 | | |
47 | | - | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | | - | |
52 | | - | |
53 | | - | |
54 | | - | |
55 | | - | |
56 | | - | |
57 | | - | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | | - | |
65 | 30 | | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | | - | |
74 | | - | |
75 | | - | |
76 | | - | |
77 | | - | |
78 | | - | |
79 | | - | |
80 | | - | |
81 | | - | |
82 | | - | |
83 | | - | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
84 | 54 | | |
85 | 55 | | |
86 | 56 | | |
| |||
93 | 63 | | |
94 | 64 | | |
95 | 65 | | |
96 | | - | |
97 | | - | |
| 66 | + | |
| 67 | + | |
98 | 68 | | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
99 | 72 | | |
100 | 73 | | |
101 | 74 | | |
| |||
107 | 80 | | |
108 | 81 | | |
109 | 82 | | |
110 | | - | |
111 | | - | |
112 | | - | |
| 83 | + | |
113 | 84 | | |
114 | | - | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
115 | 89 | | |
116 | | - | |
117 | | - | |
118 | | - | |
119 | | - | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
120 | 97 | | |
| 98 | + | |
121 | 99 | | |
122 | 100 | | |
123 | 101 | | |
124 | 102 | | |
125 | | - | |
126 | | - | |
127 | | - | |
128 | | - | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
129 | 110 | | |
| 111 | + | |
130 | 112 | | |
131 | 113 | | |
132 | 114 | | |
133 | 115 | | |
134 | | - | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
135 | 121 | | |
| 122 | + | |
136 | 123 | | |
137 | 124 | | |
138 | 125 | | |
| |||
158 | 145 | | |
159 | 146 | | |
160 | 147 | | |
161 | | - | |
162 | | - | |
163 | | - | |
| 148 | + | |
164 | 149 | | |
165 | 150 | | |
166 | 151 | | |
| |||
0 commit comments