Skip to content

Commit

Permalink
JDBC Sources: Wrap SQLTransientException with ConfigErrorException (#…
Browse files Browse the repository at this point in the history
…19711)

* JDBC Sources: Wrap SQLTransientException with ConfigErrorException

* JDBC Sources: Wrap SQLTransientException with ConfigErrorException

* removed unneeded exception handling in check method

* updated exception's message

* add catch clause to avoid PMD rule violation

* add original exception to the Throwable

* add catch clause
  • Loading branch information
VitaliiMaltsev committed Dec 1, 2022
1 parent b1c50b8 commit 9736352
Showing 1 changed file with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package io.airbyte.db.jdbc;

import com.google.errorprone.annotations.MustBeClosed;
import io.airbyte.commons.exceptions.ConfigErrorException;
import io.airbyte.commons.exceptions.ConnectionErrorException;
import io.airbyte.commons.functional.CheckedConsumer;
import io.airbyte.commons.functional.CheckedFunction;
Expand All @@ -14,6 +15,7 @@
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.SQLTransientException;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -76,8 +78,12 @@ public <T> Stream<T> unsafeResultSetQuery(final CheckedFunction<Connection, Resu
@Override
public DatabaseMetaData getMetaData() throws SQLException {
try (final Connection connection = dataSource.getConnection()) {
final DatabaseMetaData metaData = connection.getMetaData();
return metaData;
return connection.getMetaData();
} catch (final SQLTransientException e) {
final String message = e.getMessage();
if (message.contains("request timed out")) {
throw new ConfigErrorException("Connection timed out. Unable to contact server. Please check your server settings or try again later", e);
}
} catch (final SQLException e) {
// Some databases like Redshift will have null cause
if (Objects.isNull(e.getCause()) || !(e.getCause() instanceof SQLException)) {
Expand All @@ -87,6 +93,7 @@ public DatabaseMetaData getMetaData() throws SQLException {
throw new ConnectionErrorException(e.getSQLState(), cause.getErrorCode(), cause.getMessage(), e);
}
}
throw new RuntimeException("Failed to get metadata fron Datasource");
}

/**
Expand Down

0 comments on commit 9736352

Please sign in to comment.