diff --git a/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/GoogleComputeEngineFallbacks.java b/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/GoogleComputeEngineFallbacks.java index 8024bd671b..573bca016b 100644 --- a/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/GoogleComputeEngineFallbacks.java +++ b/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/GoogleComputeEngineFallbacks.java @@ -16,14 +16,27 @@ */ package org.jclouds.googlecomputeengine; +import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.base.Predicates.in; +import static com.google.common.base.Throwables.propagate; +import static com.google.common.primitives.Ints.asList; import static org.jclouds.Fallbacks.valOnNotFoundOr404; +import static org.jclouds.http.HttpUtils.returnValueOnCodeOrNull; import org.jclouds.Fallback; import org.jclouds.googlecomputeengine.domain.ListPage; public final class GoogleComputeEngineFallbacks { + public static class NullOn400or404 implements Fallback { + @Override public Object createOrPropagate(Throwable t) throws Exception { + Boolean returnVal = returnValueOnCodeOrNull(checkNotNull(t, "throwable"), false, in(asList(400, 404))); + if (returnVal != null) + return null; + throw propagate(t); + } + } public static final class EmptyListPageOnNotFoundOr404 implements Fallback { - public ListPage createOrPropagate(Throwable t) throws Exception { + @Override public ListPage createOrPropagate(Throwable t) throws Exception { return valOnNotFoundOr404(ListPage.create(null, null, null), t); } } diff --git a/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/ProjectApi.java b/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/ProjectApi.java index effbc833be..573aaa5c7a 100644 --- a/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/ProjectApi.java +++ b/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/ProjectApi.java @@ -30,7 +30,7 @@ import javax.ws.rs.PathParam; import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; -import org.jclouds.Fallbacks.NullOnNotFoundOr404; +import org.jclouds.googlecomputeengine.GoogleComputeEngineFallbacks.NullOn400or404; import org.jclouds.googlecomputeengine.binders.MetadataBinder; import org.jclouds.googlecomputeengine.domain.Operation; import org.jclouds.googlecomputeengine.domain.Project; @@ -59,7 +59,7 @@ public interface ProjectApi { @GET @OAuthScopes(COMPUTE_READONLY_SCOPE) @Consumes(MediaType.APPLICATION_JSON) - @Fallback(NullOnNotFoundOr404.class) + @Fallback(NullOn400or404.class) @Path("/projects/{project}") Project get(@PathParam("project") String projectName);