Skip to content

[Feat]: Check throwable.cause instance of A2AError in JSONRPCHandler#convertToSendStreamingMessageResponse #648

@yuyu123-yuyu

Description

@yuyu123-yuyu

Is your feature request related to a problem? Please describe.

Hello, I ran into the following problem:
I am implementing a customized JSONRPC server, where I use DefaultRequestHandler, JSONRPCHandler from this project, and implemented a customized AgentExecutor.

When I am debuging the SendStreamingMessage method, I throw an UnsupportedOperationError from MyAgentExecutor, but got a -32603 InternalError from the SendStreamingMessageResponse.

It seems that in this function,


it receives a java.util.concurrent.CompletionException, instead of the UnsupportedOperationError.

Describe the solution you'd like

It seems that the CompletionException has the UnsupportedOperationError as the cause field.

I am wondering if it is reasonable to also check for the cause field of the throwable, to see if it is an instance of the A2AError class. If it is, send the according response.

Something like:

@Override
public void onError(Throwable throwable) {
    if (throwable instanceof A2AError jsonrpcError) {
        tube.send(new SendStreamingMessageResponse(requestId, jsonrpcError));
    } else if (throwable.getCause() != null && throwable.getCause() instanceof A2AError jsonrpcError) { // also check the cause field
        tube.send(new SendStreamingMessageResponse(requestId, jsonrpcError));
    } else {
        tube.send(
                new SendStreamingMessageResponse(
                        requestId, new
                        InternalError(throwable.getMessage())));
    }
    onComplete();
}

It would be helpful if you can take a look. Thanks!

Describe alternatives you've considered

No response

Additional context

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions