All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.zalando.riptide.faults.FaultClassifier Maven / Gradle / Ivy

There is a newer version: 4.1.0
Show newest version
package org.zalando.riptide.faults;

import org.apiguardian.api.API;

import java.util.concurrent.CompletableFuture;
import java.util.function.Function;

import static org.apiguardian.api.API.Status.STABLE;

@API(status = STABLE)
public interface FaultClassifier {

    /**
     * Classifies the given {@link Throwable throwable} into transient and persistent faults.
     *
     * @param throwable the throwable
     * @return the given throwable if it's considered permanent, or a {@link TransientFaultException} with the given
     * throwable as its cause, if it's considered transient
     */
    Throwable classify(final Throwable throwable);

    /**
     * Provides a function that classifies its argument using {@link #classify(Throwable)} and throws it. This function
     * is supposed to be used in conjunction with {@link CompletableFuture#exceptionally(Function)}.
     *
     * @see CompletableFuture#exceptionally(Function)
     * @param throwable the throwable
     * @param  generic return type
     * @return never, always throws
     * @throws Throwable either argument or wrapped argument
     */
    default  T classifyExceptionally(final Throwable throwable) throws Throwable {
        throw classify(throwable);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy