Skip to content

Commit 5a82c85

Browse files
authored
Feat: Update universe domain exception error code/message (#3113)
* Feat: Update universe domain exception error code/message * Feat: Update universe domain exception error code/message
1 parent 2156f02 commit 5a82c85

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

google-cloud-bigquery/pom.xml

+4
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@
5050
<groupId>org.checkerframework</groupId>
5151
<artifactId>checker-qual</artifactId>
5252
</dependency>
53+
<dependency>
54+
<groupId>com.google.auth</groupId>
55+
<artifactId>google-auth-library-credentials</artifactId>
56+
</dependency>
5357
<dependency>
5458
<groupId>com.google.auth</groupId>
5559
<artifactId>google-auth-library-oauth2-http</artifactId>

google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/spi/v2/HttpBigQueryRpc.java

+6-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import static java.net.HttpURLConnection.HTTP_CREATED;
2020
import static java.net.HttpURLConnection.HTTP_NOT_FOUND;
2121
import static java.net.HttpURLConnection.HTTP_OK;
22+
import static java.net.HttpURLConnection.HTTP_UNAUTHORIZED;
2223

2324
import com.google.api.client.http.ByteArrayContent;
2425
import com.google.api.client.http.GenericUrl;
@@ -116,7 +117,11 @@ private static BigQueryException translate(IOException exception) {
116117

117118
private void validateRPC() throws BigQueryException, IOException {
118119
if (!this.options.hasValidUniverseDomain()) {
119-
throw new BigQueryException(BigQueryException.UNKNOWN_CODE, "Invalid universe domain");
120+
String errorMessage =
121+
String.format(
122+
"The configured universe domain %s does not match the universe domain found in the credentials %s. If you haven't configured the universe domain explicitly, `googleapis.com` is the default.",
123+
this.options.getUniverseDomain(), this.options.getCredentials().getUniverseDomain());
124+
throw new BigQueryException(HTTP_UNAUTHORIZED, errorMessage);
120125
}
121126
}
122127

google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/it/ITBigQueryTest.java

+11-2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import static com.google.cloud.bigquery.JobStatus.State.DONE;
2020
import static com.google.common.truth.Truth.assertThat;
2121
import static java.lang.System.currentTimeMillis;
22+
import static java.net.HttpURLConnection.HTTP_UNAUTHORIZED;
2223
import static org.junit.Assert.assertArrayEquals;
2324
import static org.junit.Assert.assertEquals;
2425
import static org.junit.Assert.assertFalse;
@@ -6445,8 +6446,12 @@ public void testUniverseDomainWithInvalidUniverseDomain() {
64456446
bigQuery.listDatasets("bigquery-public-data");
64466447
fail("RPCs to invalid universe domain should fail");
64476448
} catch (BigQueryException e) {
6449+
assertEquals(e.getCode(), HTTP_UNAUTHORIZED);
64486450
assertNotNull(e.getMessage());
6449-
assertThat((e.getMessage().contains("Invalid universe domain"))).isTrue();
6451+
assertThat(
6452+
(e.getMessage()
6453+
.contains("does not match the universe domain found in the credentials")))
6454+
.isTrue();
64506455
}
64516456
}
64526457

@@ -6466,8 +6471,12 @@ public void testInvalidUniverseDomainWithMismatchCredentials() {
64666471
bigQuery.listDatasets("bigquery-public-data");
64676472
fail("RPCs to invalid universe domain should fail");
64686473
} catch (BigQueryException e) {
6474+
assertEquals(e.getCode(), HTTP_UNAUTHORIZED);
64696475
assertNotNull(e.getMessage());
6470-
assertThat((e.getMessage().contains("Invalid universe domain"))).isTrue();
6476+
assertThat(
6477+
(e.getMessage()
6478+
.contains("does not match the universe domain found in the credentials")))
6479+
.isTrue();
64716480
}
64726481
}
64736482

0 commit comments

Comments
 (0)