briandilley/jsonrpc4j

About @ jsonrpcerrors and @ jsonrpcclientexception

qq454549798 opened this issue · 0 comments

In the use of jsonrpc exceptions, it is troublesome to annotate @ jsonrpcerrors. If there are different exceptions in a method, multiple items need to be configured in @ jsonrpcerrors.

In the exception handling class defaulterrorresolver, it is recommended to adjust the method resolveerror to:

public JsonError resolveError(Throwable t, Method method, List arguments) {

//Add an exception judgment and bring in the error code

if (t instanceof JsonRpcClientException) {

JsonRpcClientException rpcException = ((JsonRpcClientException) t);

return new JsonError(rpcException.getCode(), rpcException.getMessage(), new ErrorData(t.getClass().getName(), rpcException.getMessage()));

}

return new JsonError(ERROR_NOT_HANDLED.code, t.getMessage(), new ErrorData(t.getClass().getName(), t.getMessage()));

}

In this way, when trying to catch, you can directly handle exceptions through new jsonrpcclientexception (code, message, jsonnode).

If you don't rewrite the code here, the code here can't be customized. It's always 36001