Skip to content

Commit

Permalink
refactor null check
Browse files Browse the repository at this point in the history
  • Loading branch information
ptiurin committed Jul 1, 2024
1 parent cd57b02 commit 855f4c7
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
7 changes: 4 additions & 3 deletions src/main/java/com/firebolt/jdbc/exception/SQLState.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 855f4c7

Please sign in to comment.