Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
import com.google.api.gax.retrying.TimedAttemptSettings;
import com.google.api.gax.retrying.TimedRetryAlgorithm;
import com.google.api.gax.retrying.TimedRetryAlgorithmWithContext;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.google.api.services.bigquery.model.ErrorProto;
import com.google.api.services.bigquery.model.Job;
import java.time.Duration;
import java.util.Iterator;
import java.util.UUID;
Expand Down Expand Up @@ -222,21 +222,11 @@ private String getErrorDescFromResponse(ResponseT previousResponse) {
following logic based on response body of jobs.insert method, so far the only
known case where a response with status code 200 may contain an error message
*/
try {
JsonObject responseJson =
JsonParser.parseString(previousResponse.toString()).getAsJsonObject();
if (responseJson.has("status") && responseJson.getAsJsonObject("status").has("errorResult")) {
return responseJson
.getAsJsonObject("status")
.getAsJsonObject("errorResult")
.get("message")
.toString();
} else {
return null;
}
} catch (Exception e) {
// exceptions here implies no error message present in response, returning null
return null;
if (previousResponse instanceof Job) {
Job job = (Job) previousResponse;
ErrorProto error = job.getStatus() != null ? job.getStatus().getErrorResult() : null;
return error != null ? error.getMessage() : null;
}
return null;
Comment on lines +225 to +230
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This is a great performance improvement. For better readability and to avoid potential maintenance issues with chained ternary operators, consider refactoring this block to use nested if statements. This makes the null-checking logic more explicit and easier to understand at a glance.

    if (previousResponse instanceof Job) {
      Job job = (Job) previousResponse;
      com.google.api.services.bigquery.model.JobStatus status = job.getStatus();
      if (status != null) {
        ErrorProto error = status.getErrorResult();
        if (error != null) {
          return error.getMessage();
        }
      }
    }
    return null;

}
}
Loading