1

How can I throw jsonrpc error object with user defined code, message and data from spring boot project? I tried below code, unfortunately passed code and data are not getting inside error. But I am getting passed message.

I have mentioned my code below, I want to get full data object information in error block. please help me on this

RPC request:

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "process",
  "params": {
    "request": {
      "origin": "TEST",
      "quantity": 1
    }
  }
}

RPC response:

{
    "jsonrpc": "2.0",
    "id": 1,
    "error": {
        "code": -32001,
        "message": "Invalid request param",
        "data": {
            "exceptionTypeName": "com.googlecode.jsonrpc4j.JsonRpcClientException",
            "message": "Invalid request param"
        }
    }
}

JAVA Code for throw exception

        ObjectMapper mapper = new ObjectMapper();
        NodeBean data = new NodeBean();
        data.setErrorCode("E400");
        data.setErrorMessage("Test message from error data object");
        JsonNode jsonNode = mapper.valueToTree(data);
        throw new JsonRpcClientException(1, "Invalid request param", jsonNode);
Progman
  • 16,827
  • 6
  • 33
  • 48
Rojan
  • 11
  • 2
  • You have to pass a `JsonNode` object as the third parameter for the `JsonRpcClientException` constructor. – Progman Dec 30 '19 at 21:38
  • Thanks for your reply, I had tried by setting JsonNode. But it was not working, please check my code – Rojan Dec 31 '19 at 10:07
  • Please take the [tour] to learn how Stack Overflow works and read [ask] on how to improve the quality of your question. Then [edit] your question to include the source code you have as a [mcve], which can be compiled and tested by others. – Progman Dec 31 '19 at 10:30
  • JsonRpc 1.5.3 version does not handle the passed JsonNode object as data. Due to this issue, am not getting the data object in error block. Check the below code in Jar AnnotationsErrorResolver.java public JsonError resolveError( return new JsonError(resolver.code(), message, new ErrorData(resolver.exception().getName(), message)); – Rojan Jan 02 '20 at 17:32

0 Answers0