fix: expose HTTP status code in JSONRPCTransport errors#798
Open
pratik3558 wants to merge 4 commits intoa2aproject:mainfrom
Open
fix: expose HTTP status code in JSONRPCTransport errors#798pratik3558 wants to merge 4 commits intoa2aproject:mainfrom
pratik3558 wants to merge 4 commits intoa2aproject:mainfrom
Conversation
4ee1f77 to
701ab66
Compare
Contributor
There was a problem hiding this comment.
Code Review
This pull request enhances HTTP error handling by introducing A2AClientHTTPError as a structured cause within A2AClientException, allowing callers to retrieve the HTTP status code and response body. Feedback highlights a missing throws declaration for A2AClientException in the sendPostRequest method, which would lead to a compilation error, and suggests refactoring duplicated error message strings for better maintainability.
701ab66 to
ce324f7
Compare
chinmayb0
approved these changes
Apr 17, 2026
suthirrpreethum
approved these changes
Apr 17, 2026
akupireddy
reviewed
Apr 17, 2026
Previously, when the JSONRPC transport received a non-2xx HTTP response,
it threw a plain IOException with the status code embedded as a string
(e.g. "Request failed 503"). This made it impossible for callers to
programmatically distinguish 4xx from 5xx errors without fragile string
parsing.
This change makes the structured HTTP status code available while
remaining fully backward compatible:
- JSONRPCTransport.sendPostRequest now throws A2AClientException with an
A2AClientHTTPError as the cause, instead of a plain IOException.
All transport methods already declared 'throws A2AClientException' and
already had 'catch (A2AClientException e) { throw e; }', so no caller
signatures change.
- A2AClientHTTPError gains a new 'responseBody' field (and getResponseBody()
accessor) so callers can also inspect the raw error payload returned by
the server (e.g. a gateway's JSON error body on a 429 or 503).
The existing 'code', 'message', and getCode() are preserved unchanged.
The old Object-typed constructor is deprecated in favour of the new
String-typed one that actually stores the body.
Callers that want the status code can now opt in with a simple instanceof
check, while existing catch blocks for A2AClientException continue to work
without modification:
} catch (A2AClientException e) {
if (e.getCause() instanceof A2AClientHTTPError httpErr) {
int status = httpErr.getCode(); // e.g. 503
String body = httpErr.getResponseBody(); // raw response body
}
}
Fixes a2aproject#799
794811d to
3fc3085
Compare
29fa5df to
efe00bc
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Previously, when the JSONRPC transport received a non-2xx HTTP response, it threw a plain IOException with the status code embedded as a string (e.g. "Request failed 503"). This made it impossible for callers to programmatically distinguish 4xx from 5xx errors without fragile string parsing.
This change makes the structured HTTP status code available while remaining fully backward compatible:
JSONRPCTransport.sendPostRequest now throws A2AClientException with an A2AClientHTTPError as the cause, instead of a plain IOException. All transport methods already declared 'throws A2AClientException' and already had 'catch (A2AClientException e) { throw e; }', so no caller signatures change.
A2AClientHTTPError gains a new 'responseBody' field (and getResponseBody() accessor) so callers can also inspect the raw error payload returned by the server (e.g. a gateway's JSON error body on a 429 or 503). The existing 'code', 'message', and getCode() are preserved unchanged. The old Object-typed constructor is deprecated in favour of the new String-typed one that actually stores the body.
Callers that want the status code can now opt in with a simple instanceof check, while existing catch blocks for A2AClientException continue to work without modification:
Description
Thank you for opening a Pull Request!
Before submitting your PR, there are a few things you can do to make sure it goes smoothly:
CONTRIBUTINGGuide.fix:which represents bug fixes, and correlates to a SemVer patch.feat:represents a new feature, and correlates to a SemVer minor.feat!:, orfix!:,refactor!:, etc., which represent a breaking change (indicated by the!) and will result in a SemVer major.Fixes #799 🦕