Skip to content

Commit

Permalink
Improve error message for unsupported connection mode (sentinel)
Browse files Browse the repository at this point in the history
  • Loading branch information
Veirisa committed Mar 2, 2024
1 parent 7ac1805 commit 1e58b51
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions driver/src/main/java/jdbc/RedisConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,14 @@ public void checkMode() throws SQLException {
}
RedisMode clientMode = client.getMode();
if (clientMode != serverMode) {
String clientModeName = toLowerCase(clientMode.name());
String serverModeName = toLowerCase(serverMode.name());
String serverURLPrefix = RedisClientFactory.getURLPrefix(serverMode);
String urlFix = serverURLPrefix != null ? String.format("\nPlease change the URL prefix to \"%s\".", serverURLPrefix) : null;
throw new SQLException(String.format("The connection mode \"%s\" does not match the server mode \"%s\".%s",
toLowerCase(clientMode.name()), toLowerCase(serverMode.name()), urlFix));
String messageTail = serverURLPrefix != null
? String.format("Please change the URL prefix to \"%s\".", serverURLPrefix)
: String.format("Meanwhile, the connection mode \"%s\" is not supported at the moment.", serverModeName);
throw new SQLException(String.format("The connection mode \"%s\" does not match the server mode \"%s\".\n%s",
clientModeName, serverModeName, messageTail));
}
}

Expand Down

0 comments on commit 1e58b51

Please sign in to comment.