mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-29 10:30:38 +00:00
Return json response if available in error data field
This commit is contained in:
parent
fc8b6d0fcb
commit
f58f85ef60
1 changed files with 17 additions and 4 deletions
|
@ -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 <T> void parseParamsAndRunCommand(
|
||||
final ObjectMapper objectMapper,
|
||||
final TreeNode params,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue