From 2e38f0219904e8d52bbd10de15610d5814f5e30b Mon Sep 17 00:00:00 2001 From: Marco Ziccardi Date: Thu, 21 Jan 2016 11:09:32 +0100 Subject: [PATCH] Add code to initialize BigQueryError in BigQueryException --- .../google/gcloud/bigquery/BigQueryException.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/gcloud-java-bigquery/src/main/java/com/google/gcloud/bigquery/BigQueryException.java b/gcloud-java-bigquery/src/main/java/com/google/gcloud/bigquery/BigQueryException.java index b0cca68e3e0a..d07843583bee 100644 --- a/gcloud-java-bigquery/src/main/java/com/google/gcloud/bigquery/BigQueryException.java +++ b/gcloud-java-bigquery/src/main/java/com/google/gcloud/bigquery/BigQueryException.java @@ -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; @@ -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; } /**