diff --git a/src/main/java/com/firebolt/jdbc/exception/SQLState.java b/src/main/java/com/firebolt/jdbc/exception/SQLState.java index 3fcceb0df..5912a1cb6 100644 --- a/src/main/java/com/firebolt/jdbc/exception/SQLState.java +++ b/src/main/java/com/firebolt/jdbc/exception/SQLState.java @@ -103,7 +103,8 @@ public enum SQLState { ASSERT_FAILURE("P0004"), INTERNAL_ERROR("XX000"), DATA_CORRUPTED("XX001"), - INDEX_CORRUPTED("XX002"); + INDEX_CORRUPTED("XX002"), + STATE_NOT_DEFINED(null); private final String code; @@ -117,10 +118,10 @@ public String getCode() { public static SQLState fromCode(String sqlState) { for (SQLState state : SQLState.values()) { - if (state.code.equals(sqlState)) { + if (state.code != null && state.code.equals(sqlState)) { return state; } } - return null; + return STATE_NOT_DEFINED; } } diff --git a/src/main/java/com/firebolt/jdbc/service/FireboltAuthenticationService.java b/src/main/java/com/firebolt/jdbc/service/FireboltAuthenticationService.java index 323d20e4e..a03c27867 100644 --- a/src/main/java/com/firebolt/jdbc/service/FireboltAuthenticationService.java +++ b/src/main/java/com/firebolt/jdbc/service/FireboltAuthenticationService.java @@ -54,9 +54,6 @@ public FireboltConnectionTokens getConnectionTokens(String host, FireboltPropert log.log(Level.SEVERE, "Failed to connect to Firebolt", e); String msg = ofNullable(e.getErrorMessageFromServer()).map(m -> format(ERROR_MESSAGE_FROM_SERVER, m)).orElse(format(ERROR_MESSAGE, e.getMessage())); SQLState sqlState = SQLState.fromCode(e.getSQLState()); - if (sqlState == null) { - throw new FireboltException(msg, e); - } throw new FireboltException(msg, e, sqlState); } catch (Exception e) { log.log(Level.SEVERE, "Failed to connect to Firebolt", e);