com.algolia.exceptions.LaunderThrowable Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of algoliasearch Show documentation
Show all versions of algoliasearch Show documentation
Java client for Algolia Search API
The newest version!
package com.algolia.exceptions;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
public class LaunderThrowable {
private LaunderThrowable() {
// Empty.
}
/**
* 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 launder(e);
}
}
/** Launders both Interrupted and Execution exception into business exception */
public static AlgoliaRuntimeException launder(Throwable t) {
Throwable cause = t.getCause();
if (cause instanceof AlgoliaRuntimeException) {
return (AlgoliaRuntimeException) cause;
}
return new AlgoliaRuntimeException(t);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy