Skip to content

fix(rest): fall back to the HTTP error when an error body field is not a string - #1343

Merged
ehsavoie merged 1 commit into
a2aproject:mainfrom
sumitvairagar:fix/1342-rest-error-mapper-non-string-fields
Nov 20, 2026
Merged

ehsavoie merged 1 commit into
a2aproject:mainfrom
sumitvairagar:fix/1342-rest-error-mapper-non-string-fields

Conversation

@sumitvairagar

Copy link
Copy Markdown
Contributor

Fixes #1342.

RestErrorMapper called getAsString() on the message, error and reason fields of an error body. When a field was JSON null or an object, this threw UnsupportedOperationException. That exception escaped RestTransport, instead of the A2AClientException that carries the HTTP status and headers.

The mapper now reads these fields only when they are JSON primitives, and otherwise treats them as absent, so such responses map to an A2AClientHTTPError. Well-formed error bodies are handled as before. This mirrors #858, which fixed the same problem for the JSON-RPC error field.

Tests: four regression tests in RestErrorMapperTest, for a null message, a non-string message, a null error, and a null reason in details. All four fail on main and pass with this change. The REST transport module's tests pass.

…t a string

RestErrorMapper called getAsString() on the message, error and reason
fields of an error body. A JSON null or a non-primitive value made it
throw UnsupportedOperationException, which escaped RestTransport instead
of the A2AClientException that carries the HTTP status and headers.

Read these fields only when they are JSON primitives and otherwise treat
them as absent, so such responses map to an A2AClientHTTPError.

Fixes a2aproject#1342
@ehsavoie
ehsavoie merged commit 586fdd5 into a2aproject:main Nov 20, 2026
14 checks passed
@ehsavoie

Copy link
Copy Markdown
Collaborator

Thanks @sumitvairagar

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: RestErrorMapper throws UnsupportedOperationException when an error body has a null or non-string message

2 participants