|
18 | 18 |
|
19 | 19 | import static com.google.common.base.Preconditions.checkNotNull; |
20 | 20 |
|
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; |
22 | 23 | import com.google.api.gax.retrying.ResultRetryAlgorithm; |
23 | 24 | import com.google.api.gax.retrying.ResultRetryAlgorithmWithContext; |
24 | 25 | import com.google.api.gax.retrying.RetryAlgorithm; |
@@ -223,31 +224,11 @@ private String getErrorDescFromResponse(ResponseT previousResponse) { |
223 | 224 | following logic based on response body of jobs.insert method, so far the only |
224 | 225 | known case where a response with status code 200 may contain an error message |
225 | 226 | */ |
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; |
251 | 231 | } |
| 232 | + return null; |
252 | 233 | } |
253 | 234 | } |
0 commit comments