Skip to content
Merged
Show file tree
Hide file tree
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 @@ -55,16 +55,11 @@ public BigQueryException(int code, String message, BigQueryError error) {

public BigQueryException(IOException exception) {
super(exception, true);
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"));
}
BigQueryError error = null;
if (reason() != null) {
error = new BigQueryError(reason(), location(), getMessage(), debugInfo());
}
this.error = bigqueryError;
this.error = error;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,20 +86,32 @@ public int hashCode() {
private final boolean retryable;
private final String reason;
private final boolean idempotent;
private final String location;
private final String debugInfo;

public BaseServiceException(IOException exception, boolean idempotent) {
super(message(exception), exception);
int code = UNKNOWN_CODE;
String reason = null;
String location = null;
String debugInfo = null;
if (exception instanceof GoogleJsonResponseException) {
Error error = error(((GoogleJsonResponseException) exception).getDetails());
this.code = error.code;
this.reason = error.reason;
this.retryable = error.isRetryable(retryableErrors());
} else {
this.code = UNKNOWN_CODE;
this.reason = null;
this.retryable = idempotent && isRetryable(exception);
GoogleJsonError jsonError = ((GoogleJsonResponseException) exception).getDetails();
Error error = error(jsonError);
code = error.code;
reason = error.reason;
if (reason != null) {
GoogleJsonError.ErrorInfo errorInfo = jsonError.getErrors().get(0);
location = errorInfo.getLocation();
debugInfo = (String) errorInfo.get("debugInfo");
}
}
this.code = code;
this.retryable = idempotent && isRetryable(exception);
this.reason = reason;
this.idempotent = idempotent;
this.location = location;
this.debugInfo = debugInfo;
}

public BaseServiceException(GoogleJsonError error, boolean idempotent) {
Expand All @@ -108,6 +120,8 @@ public BaseServiceException(GoogleJsonError error, boolean idempotent) {
this.reason = reason(error);
this.idempotent = idempotent;
this.retryable = idempotent && isRetryable(error);
this.location = null;
this.debugInfo = null;
}

public BaseServiceException(int code, String message, String reason, boolean idempotent) {
Expand All @@ -121,6 +135,8 @@ public BaseServiceException(int code, String message, String reason, boolean ide
this.reason = reason;
this.idempotent = idempotent;
this.retryable = idempotent && new Error(code, reason).isRetryable(retryableErrors());
this.location = null;
this.debugInfo = null;
}

protected Set<Error> retryableErrors() {
Expand Down Expand Up @@ -166,6 +182,18 @@ public boolean idempotent() {
return idempotent;
}

/**
* Returns the service location where the error causing the exception occurred. Returns
* {@code null} if not set.
*/
public String location() {
return location;
}

protected String debugInfo() {
return debugInfo;
}

protected static String reason(GoogleJsonError error) {
if (error.getErrors() != null && !error.getErrors().isEmpty()) {
return error.getErrors().get(0).getReason();
Expand Down