mirror of https://github.com/apache/jclouds.git
Store propagatable exceptions in a static field
Also include ResourceAlreadyExistsException. References JCLOUDS-438.
This commit is contained in:
parent
52f25fd284
commit
241abea734
|
@ -27,10 +27,12 @@ import org.jclouds.concurrent.TransformParallelException;
|
||||||
import org.jclouds.http.HttpResponseException;
|
import org.jclouds.http.HttpResponseException;
|
||||||
import org.jclouds.rest.AuthorizationException;
|
import org.jclouds.rest.AuthorizationException;
|
||||||
import org.jclouds.rest.InsufficientResourcesException;
|
import org.jclouds.rest.InsufficientResourcesException;
|
||||||
|
import org.jclouds.rest.ResourceAlreadyExistsException;
|
||||||
import org.jclouds.rest.ResourceNotFoundException;
|
import org.jclouds.rest.ResourceNotFoundException;
|
||||||
|
|
||||||
import com.google.common.annotations.VisibleForTesting;
|
import com.google.common.annotations.VisibleForTesting;
|
||||||
import com.google.common.base.Predicate;
|
import com.google.common.base.Predicate;
|
||||||
|
import com.google.common.collect.ImmutableList;
|
||||||
import com.google.common.reflect.TypeToken;
|
import com.google.common.reflect.TypeToken;
|
||||||
import com.google.inject.CreationException;
|
import com.google.inject.CreationException;
|
||||||
import com.google.inject.ProvisionException;
|
import com.google.inject.ProvisionException;
|
||||||
|
@ -125,8 +127,19 @@ public class Throwables2 {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Note that ordering matters to propagateIfPossible.
|
||||||
|
private static final ImmutableList<Class<? extends Throwable>> PROPAGATABLE_EXCEPTION_TYPES = ImmutableList.of(
|
||||||
|
IllegalStateException.class,
|
||||||
|
AssertionError.class,
|
||||||
|
UnsupportedOperationException.class,
|
||||||
|
IllegalArgumentException.class,
|
||||||
|
AuthorizationException.class,
|
||||||
|
ResourceAlreadyExistsException.class,
|
||||||
|
ResourceNotFoundException.class,
|
||||||
|
InsufficientResourcesException.class,
|
||||||
|
HttpResponseException.class);
|
||||||
|
|
||||||
// Note this needs to be kept up-to-date with all top-level exceptions jclouds works against
|
// Note this needs to be kept up-to-date with all top-level exceptions jclouds works against
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public static void propagateIfPossible(Throwable exception, Iterable<TypeToken<? extends Throwable>> throwables)
|
public static void propagateIfPossible(Throwable exception, Iterable<TypeToken<? extends Throwable>> throwables)
|
||||||
throws Throwable {
|
throws Throwable {
|
||||||
for (TypeToken<? extends Throwable> type : throwables) {
|
for (TypeToken<? extends Throwable> type : throwables) {
|
||||||
|
@ -135,10 +148,7 @@ public class Throwables2 {
|
||||||
throw throwable;
|
throw throwable;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (Class<Exception> propagatableExceptionType : new Class[] { IllegalStateException.class,
|
for (Class<? extends Throwable> propagatableExceptionType : PROPAGATABLE_EXCEPTION_TYPES) {
|
||||||
AssertionError.class, UnsupportedOperationException.class, IllegalArgumentException.class,
|
|
||||||
AuthorizationException.class, ResourceNotFoundException.class, InsufficientResourcesException.class,
|
|
||||||
HttpResponseException.class }) {
|
|
||||||
Throwable throwable = Throwables2.getFirstThrowableOfType(exception, propagatableExceptionType);
|
Throwable throwable = Throwables2.getFirstThrowableOfType(exception, propagatableExceptionType);
|
||||||
if (throwable != null) {
|
if (throwable != null) {
|
||||||
throw throwable;
|
throw throwable;
|
||||||
|
|
Loading…
Reference in New Issue