Skip to content

Commit 86d62b1

Browse files
committed
address pr feedback
1 parent 81e80a0 commit 86d62b1

2 files changed

Lines changed: 12 additions & 3 deletions

File tree

java-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/jdbc/BigQueryConnection.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package com.google.cloud.bigquery.jdbc;
1818

19+
import com.google.api.client.googleapis.json.GoogleJsonResponseException;
1920
import com.google.api.client.http.HttpRequestInitializer;
2021
import com.google.api.client.http.HttpTransport;
2122
import com.google.api.client.json.gson.GsonFactory;
@@ -1251,7 +1252,7 @@ public synchronized List<String> getDiscoveredProjects() {
12511252
HttpTransport transport = transportOptions.getHttpTransportFactory().create();
12521253
HttpRequestInitializer initializer = transportOptions.getHttpRequestInitializer(options);
12531254
Bigquery lowLevelBq =
1254-
new Bigquery.Builder(transport, new GsonFactory(), initializer)
1255+
new Bigquery.Builder(transport, GsonFactory.getDefaultInstance(), initializer)
12551256
.setRootUrl(options.getResolvedApiaryHost(BIGQUERY_SERVICE_NAME))
12561257
.setApplicationName(DEFAULT_JDBC_TOKEN_VALUE)
12571258
.build();
@@ -1276,9 +1277,17 @@ public synchronized List<String> getDiscoveredProjects() {
12761277
} while (pageToken != null);
12771278

12781279
this.discoveredProjectsCache = ImmutableList.copyOf(projects);
1280+
} catch (GoogleJsonResponseException e) {
1281+
LOG.warning(e, "Failed to list all accessible projects due to Google API error.");
1282+
int statusCode = e.getStatusCode();
1283+
// Only cache empty list for non-transient auth/permission errors (400, 401, 403)
1284+
if (statusCode == 400 || statusCode == 401 || statusCode == 403) {
1285+
this.discoveredProjectsCache = ImmutableList.of();
1286+
}
1287+
return ImmutableList.of();
12791288
} catch (Exception e) {
12801289
LOG.warning(e, "Failed to list all accessible projects, falling back to connection default.");
1281-
this.discoveredProjectsCache = ImmutableList.of();
1290+
return ImmutableList.of();
12821291
}
12831292
return this.discoveredProjectsCache;
12841293
}

java-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/jdbc/BigQueryDatabaseMetaData.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3688,7 +3688,7 @@ public ResultSet getSchemas(String catalog, String schemaPattern) {
36883688
Thread.currentThread().interrupt();
36893689
checkInterrupted(apiFutures);
36903690
} catch (ExecutionException e) {
3691-
LOG.warning("Error executing findMatchingDatasets task: " + e.getMessage());
3691+
LOG.warning(e, "Error executing findMatchingDatasets task.");
36923692
} catch (CancellationException e) {
36933693
LOG.warning("A findMatchingDatasets task was cancelled.");
36943694
}

0 commit comments

Comments
 (0)