Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Update universe domain exception error code/message #3113

Merged
merged 2 commits into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions google-cloud-bigquery/pom.xml
Expand Up @@ -50,6 +50,10 @@
<groupId>org.checkerframework</groupId>
<artifactId>checker-qual</artifactId>
</dependency>
<dependency>
<groupId>com.google.auth</groupId>
<artifactId>google-auth-library-credentials</artifactId>
</dependency>
<dependency>
<groupId>com.google.auth</groupId>
<artifactId>google-auth-library-oauth2-http</artifactId>
Expand Down
Expand Up @@ -19,6 +19,7 @@
import static java.net.HttpURLConnection.HTTP_CREATED;
import static java.net.HttpURLConnection.HTTP_NOT_FOUND;
import static java.net.HttpURLConnection.HTTP_OK;
import static java.net.HttpURLConnection.HTTP_UNAUTHORIZED;

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

private void validateRPC() throws BigQueryException, IOException {
if (!this.options.hasValidUniverseDomain()) {
throw new BigQueryException(BigQueryException.UNKNOWN_CODE, "Invalid universe domain");
String errorMessage =
String.format(
"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.",
this.options.getUniverseDomain(), this.options.getCredentials().getUniverseDomain());
throw new BigQueryException(HTTP_UNAUTHORIZED, errorMessage);
}
}

Expand Down
Expand Up @@ -19,6 +19,7 @@
import static com.google.cloud.bigquery.JobStatus.State.DONE;
import static com.google.common.truth.Truth.assertThat;
import static java.lang.System.currentTimeMillis;
import static java.net.HttpURLConnection.HTTP_UNAUTHORIZED;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
Expand Down Expand Up @@ -6402,8 +6403,12 @@ public void testUniverseDomainWithInvalidUniverseDomain() {
bigQuery.listDatasets("bigquery-public-data");
fail("RPCs to invalid universe domain should fail");
} catch (BigQueryException e) {
assertEquals(e.getCode(), HTTP_UNAUTHORIZED);
assertNotNull(e.getMessage());
assertThat((e.getMessage().contains("Invalid universe domain"))).isTrue();
assertThat(
(e.getMessage()
.contains("does not match the universe domain found in the credentials")))
.isTrue();
}
}

Expand All @@ -6423,8 +6428,12 @@ public void testInvalidUniverseDomainWithMismatchCredentials() {
bigQuery.listDatasets("bigquery-public-data");
fail("RPCs to invalid universe domain should fail");
} catch (BigQueryException e) {
assertEquals(e.getCode(), HTTP_UNAUTHORIZED);
assertNotNull(e.getMessage());
assertThat((e.getMessage().contains("Invalid universe domain"))).isTrue();
assertThat(
(e.getMessage()
.contains("does not match the universe domain found in the credentials")))
.isTrue();
}
}

Expand Down