Skip to content

Commit

Permalink
Merge pull request #563 from mziccard/populate-bigquery-error
Browse files Browse the repository at this point in the history
Add code to initialize BigQueryError in BigQueryException
  • Loading branch information
mziccard committed Jan 21, 2016
2 parents add5924 + 2e38f02 commit 2e8363f
Showing 1 changed file with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package com.google.gcloud.bigquery;

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

public BigQueryException(IOException exception) {
super(exception, true);
this.error = null;
BigQueryError bigqueryError = null;
if (exception instanceof GoogleJsonResponseException) {
GoogleJsonError error = ((GoogleJsonResponseException) exception).getDetails();
if (error != null && error.getErrors() != null && !error.getErrors().isEmpty()) {
GoogleJsonError.ErrorInfo errorInfo = error.getErrors().get(0);
bigqueryError = new BigQueryError(errorInfo.getReason(), errorInfo.getLocation(),
errorInfo.getMessage(), (String) error.get("debugInfo"));
}
}
this.error = bigqueryError;
}

/**
Expand Down

0 comments on commit 2e8363f

Please sign in to comment.