Skip to content

Commit 2e38f02

Browse files
committed
Add code to initialize BigQueryError in BigQueryException
1 parent add5924 commit 2e38f02

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

gcloud-java-bigquery/src/main/java/com/google/gcloud/bigquery/BigQueryException.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package com.google.gcloud.bigquery;
1818

19+
import com.google.api.client.googleapis.json.GoogleJsonError;
20+
import com.google.api.client.googleapis.json.GoogleJsonResponseException;
1921
import com.google.common.collect.ImmutableSet;
2022
import com.google.gcloud.BaseServiceException;
2123
import com.google.gcloud.RetryHelper.RetryHelperException;
@@ -53,7 +55,16 @@ public BigQueryException(int code, String message, BigQueryError error) {
5355

5456
public BigQueryException(IOException exception) {
5557
super(exception, true);
56-
this.error = null;
58+
BigQueryError bigqueryError = null;
59+
if (exception instanceof GoogleJsonResponseException) {
60+
GoogleJsonError error = ((GoogleJsonResponseException) exception).getDetails();
61+
if (error != null && error.getErrors() != null && !error.getErrors().isEmpty()) {
62+
GoogleJsonError.ErrorInfo errorInfo = error.getErrors().get(0);
63+
bigqueryError = new BigQueryError(errorInfo.getReason(), errorInfo.getLocation(),
64+
errorInfo.getMessage(), (String) error.get("debugInfo"));
65+
}
66+
}
67+
this.error = bigqueryError;
5768
}
5869

5970
/**

0 commit comments

Comments
 (0)