mirror of
https://github.com/google/nomulus.git
synced 2025-05-13 07:57:13 +02:00
Account for GoogleJsonResponseException#getDetails returning null
Apparently, this can happen ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=223163802
This commit is contained in:
parent
c2ee453745
commit
dbdc69916a
5 changed files with 22 additions and 13 deletions
|
@ -676,7 +676,7 @@ public class BigqueryConnection implements AutoCloseable {
|
||||||
bigquery.datasets().get(getProjectId(), datasetName).execute();
|
bigquery.datasets().get(getProjectId(), datasetName).execute();
|
||||||
return true;
|
return true;
|
||||||
} catch (GoogleJsonResponseException e) {
|
} catch (GoogleJsonResponseException e) {
|
||||||
if (e.getDetails().getCode() == 404) {
|
if (e.getDetails() != null && e.getDetails().getCode() == 404) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
throw e;
|
throw e;
|
||||||
|
@ -689,7 +689,7 @@ public class BigqueryConnection implements AutoCloseable {
|
||||||
bigquery.tables().get(getProjectId(), datasetName, tableName).execute();
|
bigquery.tables().get(getProjectId(), datasetName, tableName).execute();
|
||||||
return true;
|
return true;
|
||||||
} catch (GoogleJsonResponseException e) {
|
} catch (GoogleJsonResponseException e) {
|
||||||
if (e.getDetails().getCode() == 404) {
|
if (e.getDetails() != null && e.getDetails().getCode() == 404) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
throw e;
|
throw e;
|
||||||
|
|
|
@ -30,15 +30,20 @@ public final class BigqueryJobFailureException extends RuntimeException {
|
||||||
/** Delegate {@link IOException} errors, checking for {@link GoogleJsonResponseException} */
|
/** Delegate {@link IOException} errors, checking for {@link GoogleJsonResponseException} */
|
||||||
public static BigqueryJobFailureException create(IOException cause) {
|
public static BigqueryJobFailureException create(IOException cause) {
|
||||||
if (cause instanceof GoogleJsonResponseException) {
|
if (cause instanceof GoogleJsonResponseException) {
|
||||||
return create(((GoogleJsonResponseException) cause).getDetails());
|
return create((GoogleJsonResponseException) cause);
|
||||||
} else {
|
} else {
|
||||||
return new BigqueryJobFailureException(cause.getMessage(), cause, null, null);
|
return new BigqueryJobFailureException(cause.getMessage(), cause, null, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Create an error for JSON server response errors. */
|
/** Create an error for JSON server response errors. */
|
||||||
public static BigqueryJobFailureException create(GoogleJsonError error) {
|
public static BigqueryJobFailureException create(GoogleJsonResponseException cause) {
|
||||||
return new BigqueryJobFailureException(error.getMessage(), null, null, error);
|
GoogleJsonError err = cause.getDetails();
|
||||||
|
if (err != null) {
|
||||||
|
return new BigqueryJobFailureException(err.getMessage(), null, null, err);
|
||||||
|
} else {
|
||||||
|
return new BigqueryJobFailureException(cause.getMessage(), cause, null, null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Create an error from a failed job. */
|
/** Create an error from a failed job. */
|
||||||
|
|
|
@ -19,7 +19,7 @@ import static com.google.common.collect.ImmutableSet.toImmutableSet;
|
||||||
import static google.registry.model.EppResourceUtils.loadByForeignKey;
|
import static google.registry.model.EppResourceUtils.loadByForeignKey;
|
||||||
import static google.registry.util.DomainNameUtils.getSecondLevelDomain;
|
import static google.registry.util.DomainNameUtils.getSecondLevelDomain;
|
||||||
|
|
||||||
import com.google.api.client.googleapis.json.GoogleJsonError.ErrorInfo;
|
import com.google.api.client.googleapis.json.GoogleJsonError;
|
||||||
import com.google.api.client.googleapis.json.GoogleJsonResponseException;
|
import com.google.api.client.googleapis.json.GoogleJsonResponseException;
|
||||||
import com.google.api.services.dns.Dns;
|
import com.google.api.services.dns.Dns;
|
||||||
import com.google.api.services.dns.model.Change;
|
import com.google.api.services.dns.model.Change;
|
||||||
|
@ -390,12 +390,12 @@ public class CloudDnsWriter extends BaseDnsWriter {
|
||||||
try {
|
try {
|
||||||
dnsConnection.changes().create(projectId, zoneName, change).execute();
|
dnsConnection.changes().create(projectId, zoneName, change).execute();
|
||||||
} catch (GoogleJsonResponseException e) {
|
} catch (GoogleJsonResponseException e) {
|
||||||
List<ErrorInfo> errors = e.getDetails().getErrors();
|
GoogleJsonError err = e.getDetails();
|
||||||
// We did something really wrong here, just give up and re-throw
|
// We did something really wrong here, just give up and re-throw
|
||||||
if (errors.size() > 1) {
|
if (err == null || err.getErrors().size() > 1) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
String errorReason = errors.get(0).getReason();
|
String errorReason = err.getErrors().get(0).getReason();
|
||||||
|
|
||||||
if (RETRYABLE_EXCEPTION_REASONS.contains(errorReason)) {
|
if (RETRYABLE_EXCEPTION_REASONS.contains(errorReason)) {
|
||||||
throw new ZoneStateException(errorReason);
|
throw new ZoneStateException(errorReason);
|
||||||
|
|
|
@ -138,7 +138,7 @@ public class UpdateSnapshotViewAction implements Runnable {
|
||||||
.update(ref.getProjectId(), ref.getDatasetId(), ref.getTableId(), table)
|
.update(ref.getProjectId(), ref.getDatasetId(), ref.getTableId(), table)
|
||||||
.execute();
|
.execute();
|
||||||
} catch (GoogleJsonResponseException e) {
|
} catch (GoogleJsonResponseException e) {
|
||||||
if (e.getDetails().getCode() == 404) {
|
if (e.getDetails() != null && e.getDetails().getCode() == 404) {
|
||||||
bigquery.tables().insert(ref.getProjectId(), ref.getDatasetId(), table).execute();
|
bigquery.tables().insert(ref.getProjectId(), ref.getDatasetId(), table).execute();
|
||||||
} else {
|
} else {
|
||||||
logger.atWarning().withCause(e).log(
|
logger.atWarning().withCause(e).log(
|
||||||
|
|
|
@ -95,7 +95,9 @@ public class DirectoryGroupsConnection implements GroupsConnection {
|
||||||
// If the member is already in the group, ignore the error, get the existing member, and
|
// If the member is already in the group, ignore the error, get the existing member, and
|
||||||
// return it.
|
// return it.
|
||||||
GoogleJsonError err = e.getDetails();
|
GoogleJsonError err = e.getDetails();
|
||||||
if (err.getCode() == SC_NOT_FOUND && err.getMessage().equals(GROUP_NOT_FOUND_MSG)) {
|
if (err == null) {
|
||||||
|
throw e;
|
||||||
|
} else if (err.getCode() == SC_NOT_FOUND && err.getMessage().equals(GROUP_NOT_FOUND_MSG)) {
|
||||||
logger.atInfo().withCause(e).log(
|
logger.atInfo().withCause(e).log(
|
||||||
"Creating group %s during addition of member %s because the group doesn't exist.",
|
"Creating group %s during addition of member %s because the group doesn't exist.",
|
||||||
groupKey, email);
|
groupKey, email);
|
||||||
|
@ -169,7 +171,8 @@ public class DirectoryGroupsConnection implements GroupsConnection {
|
||||||
return createdGroup;
|
return createdGroup;
|
||||||
} catch (GoogleJsonResponseException e) {
|
} catch (GoogleJsonResponseException e) {
|
||||||
// Ignore the error thrown if the group already exists.
|
// Ignore the error thrown if the group already exists.
|
||||||
if (e.getDetails().getCode() == SC_CONFLICT
|
if (e.getDetails() != null
|
||||||
|
&& e.getDetails().getCode() == SC_CONFLICT
|
||||||
&& e.getDetails().getMessage().equals("Entity already exists.")) {
|
&& e.getDetails().getMessage().equals("Entity already exists.")) {
|
||||||
logger.atInfo().withCause(e).log(
|
logger.atInfo().withCause(e).log(
|
||||||
"Could not create group %s because it already exists.", groupKey);
|
"Could not create group %s because it already exists.", groupKey);
|
||||||
|
@ -204,7 +207,8 @@ public class DirectoryGroupsConnection implements GroupsConnection {
|
||||||
"%s is a member of the group %s. Got reply: %s", memberEmail, groupKey, getReply);
|
"%s is a member of the group %s. Got reply: %s", memberEmail, groupKey, getReply);
|
||||||
return true;
|
return true;
|
||||||
} catch (GoogleJsonResponseException e) {
|
} catch (GoogleJsonResponseException e) {
|
||||||
if (ERROR_MESSAGES_MEMBER_NOT_FOUND.contains(e.getDetails().getMessage())) {
|
if (e.getDetails() != null
|
||||||
|
&& ERROR_MESSAGES_MEMBER_NOT_FOUND.contains(e.getDetails().getMessage())) {
|
||||||
// This means the "get" request failed because the email wasn't part of the group.
|
// This means the "get" request failed because the email wasn't part of the group.
|
||||||
// This is expected behavior for any visitor that isn't a support group member.
|
// This is expected behavior for any visitor that isn't a support group member.
|
||||||
logger.atInfo().log(
|
logger.atInfo().log(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue