From: AsamK Date: Sun, 14 Nov 2021 14:24:21 +0000 (+0100) Subject: Return json response if available in error data field X-Git-Tag: v0.10.0~42 X-Git-Url: https://git.nmode.ca/signal-cli/commitdiff_plain/f58f85ef6012be11541597550f6ae3f7c08d8eda?ds=sidebyside Return json response if available in error data field --- diff --git a/src/main/java/org/asamk/signal/jsonrpc/SignalJsonRpcDispatcherHandler.java b/src/main/java/org/asamk/signal/jsonrpc/SignalJsonRpcDispatcherHandler.java index cb87687e..23c89f26 100644 --- a/src/main/java/org/asamk/signal/jsonrpc/SignalJsonRpcDispatcherHandler.java +++ b/src/main/java/org/asamk/signal/jsonrpc/SignalJsonRpcDispatcherHandler.java @@ -269,22 +269,35 @@ public class SignalJsonRpcDispatcherHandler { e.getMessage(), null)); } catch (UserErrorException e) { - throw new JsonRpcException(new JsonRpcResponse.Error(USER_ERROR, e.getMessage(), null)); + throw new JsonRpcException(new JsonRpcResponse.Error(USER_ERROR, + e.getMessage(), + getErrorDataNode(objectMapper, result))); } catch (IOErrorException e) { - throw new JsonRpcException(new JsonRpcResponse.Error(IO_ERROR, e.getMessage(), null)); + throw new JsonRpcException(new JsonRpcResponse.Error(IO_ERROR, + e.getMessage(), + getErrorDataNode(objectMapper, result))); } catch (UntrustedKeyErrorException e) { - throw new JsonRpcException(new JsonRpcResponse.Error(UNTRUSTED_KEY_ERROR, e.getMessage(), null)); + throw new JsonRpcException(new JsonRpcResponse.Error(UNTRUSTED_KEY_ERROR, + e.getMessage(), + getErrorDataNode(objectMapper, result))); } catch (Throwable e) { logger.error("Command execution failed", e); throw new JsonRpcException(new JsonRpcResponse.Error(JsonRpcResponse.Error.INTERNAL_ERROR, e.getMessage(), - null)); + getErrorDataNode(objectMapper, result))); } Object output = result[0] == null ? Map.of() : result[0]; return objectMapper.valueToTree(output); } + private JsonNode getErrorDataNode(final ObjectMapper objectMapper, final Object[] result) { + if (result[0] == null) { + return null; + } + return objectMapper.valueToTree(Map.of("response", result[0])); + } + private void parseParamsAndRunCommand( final ObjectMapper objectMapper, final TreeNode params,