Skip to content
This repository was archived by the owner on Mar 23, 2026. It is now read-only.

Commit 9341a76

Browse files
committed
Update error handling
1 parent 22987b6 commit 9341a76

1 file changed

Lines changed: 7 additions & 26 deletions

File tree

google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQueryRetryAlgorithm.java

Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818

1919
import static com.google.common.base.Preconditions.checkNotNull;
2020

21-
import com.google.api.client.json.GenericJson;
21+
import com.google.api.services.bigquery.model.ErrorProto;
22+
import com.google.api.services.bigquery.model.Job;
2223
import com.google.api.gax.retrying.ResultRetryAlgorithm;
2324
import com.google.api.gax.retrying.ResultRetryAlgorithmWithContext;
2425
import com.google.api.gax.retrying.RetryAlgorithm;
@@ -223,31 +224,11 @@ private String getErrorDescFromResponse(ResponseT previousResponse) {
223224
following logic based on response body of jobs.insert method, so far the only
224225
known case where a response with status code 200 may contain an error message
225226
*/
226-
try {
227-
if (previousResponse instanceof GenericJson) {
228-
if (((GenericJson)previousResponse).containsKey("status")){
229-
Object o1 = ((GenericJson)previousResponse).get("status");
230-
if (o1 instanceof GenericJson && ((GenericJson)o1).containsKey("errorResult")){
231-
Object o2 = ((GenericJson)o1).get("errorStatus");
232-
return ((GenericJson)o2).get("message").toString();
233-
}
234-
}
235-
return null;
236-
}
237-
JsonObject responseJson =
238-
JsonParser.parseString(previousResponse.toString()).getAsJsonObject();
239-
if (responseJson.has("status") && responseJson.getAsJsonObject("status").has("errorResult")) {
240-
return responseJson
241-
.getAsJsonObject("status")
242-
.getAsJsonObject("errorResult")
243-
.get("message")
244-
.toString();
245-
} else {
246-
return null;
247-
}
248-
} catch (Exception e) {
249-
// exceptions here implies no error message present in response, returning null
250-
return null;
227+
if (previousResponse instanceof Job) {
228+
Job job = (Job)previousResponse;
229+
ErrorProto error = job.getStatus() != null ? job.getStatus().getErrorResult() : null;
230+
return error != null ? error.getMessage() : null;
251231
}
232+
return null;
252233
}
253234
}

0 commit comments

Comments
 (0)