com.algolia.search.exceptions.LaunderThrowable Maven / Gradle / Ivy
The newest version!
package com.algolia.search.exceptions;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
@SuppressWarnings("WeakerAccess")
public class LaunderThrowable {
/**
* Performs a get() on the asynchronous method. Launders both Interrupted and Execution exception
* to business exception
*
* @param f The CompletableFuture to block on.
*/
public static T await(CompletableFuture f) {
try {
return f.get();
} catch (InterruptedException | ExecutionException e) {
throw LaunderThrowable.launder(e);
}
}
/** Launders both Interrupted and Execution exception into business exception */
public static RuntimeException launder(Throwable t) {
if (t.getCause() instanceof AlgoliaApiException) {
throw (AlgoliaApiException) t.getCause();
}
if (t.getCause() instanceof AlgoliaRetryException) {
throw (AlgoliaRetryException) t.getCause();
}
if (t.getCause() instanceof AlgoliaRuntimeException) {
throw (AlgoliaRuntimeException) t.getCause();
}
throw new AlgoliaRuntimeException(t);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy