Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: googleapis/google-cloud-java
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 48f68bfcea0bafe139abf7bd2d8b4a900ff1d1b3
Choose a base ref
..
head repository: googleapis/google-cloud-java
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 231fe428d6fb614a612fc70c40ad30ac678a09e9
Choose a head ref
Showing with 20 additions and 44 deletions.
  1. +20 −44 gcloud-java-compute/src/main/java/com/google/gcloud/spi/DefaultComputeRpc.java
Original file line number Diff line number Diff line change
@@ -250,20 +250,6 @@ public License getLicense(String project, String license, Map<Option, ?> options
}
}

/**
* This method returns {@code null} if the error code of {@code exception} was 404, re-throws the
* exception otherwise.
*
* @throws ComputeException if the error code of {@code exception} was not 404
*/
private static <T> T nullForNotFound(IOException exception) {
ComputeException serviceException = translate(exception);
if (serviceException.code() == HTTP_NOT_FOUND) {
return (T) null;
}
throw serviceException;
}

@Override
public Operation getGlobalOperation(String operation, Map<Option, ?> options) {
try {
@@ -272,11 +258,7 @@ public Operation getGlobalOperation(String operation, Map<Option, ?> options) {
.setFields(FIELDS.getString(options))
.execute();
} catch (IOException ex) {
ComputeException serviceException = translate(ex);
if (serviceException.code() == HTTP_NOT_FOUND) {
return null;
}
throw serviceException;
return nullForNotFound(ex);
}
}

@@ -303,11 +285,7 @@ public boolean deleteGlobalOperation(String operation) {
compute.globalOperations().delete(this.options.projectId(), operation).execute();
return true;
} catch (IOException ex) {
ComputeException serviceException = translate(ex);
if (serviceException.code() == HTTP_NOT_FOUND) {
return false;
}
throw serviceException;
return nullForNotFound(ex);
}
}

@@ -319,11 +297,7 @@ public Operation getRegionOperation(String region, String operation, Map<Option,
.setFields(FIELDS.getString(options))
.execute();
} catch (IOException ex) {
ComputeException serviceException = translate(ex);
if (serviceException.code() == HTTP_NOT_FOUND) {
return null;
}
throw serviceException;
return nullForNotFound(ex);
}
}

@@ -351,11 +325,7 @@ public boolean deleteRegionOperation(String region, String operation) {
compute.regionOperations().delete(this.options.projectId(), region, operation).execute();
return true;
} catch (IOException ex) {
ComputeException serviceException = translate(ex);
if (serviceException.code() == HTTP_NOT_FOUND) {
return false;
}
throw serviceException;
return nullForNotFound(ex);
}
}

@@ -367,11 +337,7 @@ public Operation getZoneOperation(String zone, String operation, Map<Option, ?>
.setFields(FIELDS.getString(options))
.execute();
} catch (IOException ex) {
ComputeException serviceException = translate(ex);
if (serviceException.code() == HTTP_NOT_FOUND) {
return null;
}
throw serviceException;
return nullForNotFound(ex);
}
}

@@ -399,11 +365,21 @@ public boolean deleteZoneOperation(String zone, String operation) {
compute.zoneOperations().delete(this.options.projectId(), zone, operation).execute();
return true;
} catch (IOException ex) {
ComputeException serviceException = translate(ex);
if (serviceException.code() == HTTP_NOT_FOUND) {
return false;
}
throw serviceException;
return nullForNotFound(ex);
}
}

/**
* This method returns {@code null} if the error code of {@code exception} was 404, re-throws the
* exception otherwise.
*
* @throws ComputeException if the error code of {@code exception} was not 404
*/
private static <T> T nullForNotFound(IOException exception) {
ComputeException serviceException = translate(exception);
if (serviceException.code() == HTTP_NOT_FOUND) {
return (T) null;
}
throw serviceException;
}
}