- } catch (UserErrorException e) {
- 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(),
- getErrorDataNode(objectMapper, result)));
- } catch (UntrustedKeyErrorException e) {
- throw new JsonRpcException(new JsonRpcResponse.Error(UNTRUSTED_KEY_ERROR,
- e.getMessage(),
- getErrorDataNode(objectMapper, result)));
+ } catch (CommandException ce) {
+ switch (ce) {
+ case UserErrorException e -> throw new JsonRpcException(new JsonRpcResponse.Error(USER_ERROR,
+ e.getMessage(),
+ getErrorDataNode(objectMapper, result)));
+ case IOErrorException e -> throw new JsonRpcException(new JsonRpcResponse.Error(IO_ERROR,
+ e.getMessage(),
+ getErrorDataNode(objectMapper, result)));
+ case UntrustedKeyErrorException e -> throw new JsonRpcException(new JsonRpcResponse.Error(
+ UNTRUSTED_KEY_ERROR,
+ e.getMessage(),
+ getErrorDataNode(objectMapper, result)));
+ case RateLimitErrorException e -> throw new JsonRpcException(new JsonRpcResponse.Error(RATELIMIT_ERROR,
+ e.getMessage(),
+ getErrorDataNode(objectMapper, result)));
+ case UnexpectedErrorException e -> {
+ logger.error("Command execution failed with unexpected error", e);
+ throw new JsonRpcException(new JsonRpcResponse.Error(JsonRpcResponse.Error.INTERNAL_ERROR,
+ e.getMessage() + " (" + e.getClass().getSimpleName() + ")",
+ getErrorDataNode(objectMapper, result)));
+ }
+ }