feat: enhance error handling with custom error code preservation (#653)
- Improve McpClientSession error handling to preserve custom error codes and data from McpError instances. - Add aggregated exception messages to error data field for better debugging. - Include test coverage for various McpClientSession error scenarios. Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
This commit is contained in:
parent
6e9af40bcb
commit
476f9db36f
1 changed files with 160 additions and 39 deletions
|
|
@ -166,9 +166,15 @@ public class McpClientSession implements McpSession {
|
|||
else if (message instanceof McpSchema.JSONRPCRequest request) {
|
||||
logger.debug("Received request: {}", request);
|
||||
handleIncomingRequest(request).onErrorResume(error -> {
|
||||
|
||||
McpSchema.JSONRPCResponse.JSONRPCError jsonRpcError = (error instanceof McpError mcpError
|
||||
&& mcpError.getJsonRpcError() != null) ? mcpError.getJsonRpcError()
|
||||
// TODO: add error message through the data field
|
||||
: new McpSchema.JSONRPCResponse.JSONRPCError(McpSchema.ErrorCodes.INTERNAL_ERROR,
|
||||
error.getMessage(), McpError.aggregateExceptionMessages(error));
|
||||
|
||||
var errorResponse = new McpSchema.JSONRPCResponse(McpSchema.JSONRPC_VERSION, request.id(), null,
|
||||
new McpSchema.JSONRPCResponse.JSONRPCError(McpSchema.ErrorCodes.INTERNAL_ERROR,
|
||||
error.getMessage(), null));
|
||||
jsonRpcError);
|
||||
return Mono.just(errorResponse);
|
||||
}).flatMap(this.transport::sendMessage).onErrorComplete(t -> {
|
||||
logger.warn("Issue sending response to the client, ", t);
|
||||
|
|
|
|||
Loading…
Reference in a new issue