T - the type of itempublic class UniOnFailure<T> extends Object
The upstream uni has sent us a failure, this class lets you decide what need to be done in this case. Typically,
you can recover with a fallback item (recoverWithItem(Object)), or with another Uni
(recoverWithUni(Uni)). You can also retry (retry()). Maybe, you just want to look at the failure
(invoke(Consumer)).
You can configure the type of failure on which your handler is called using:
uni.onFailure(IOException.class).recoverWithItem("boom")
uni.onFailure(IllegalStateException.class).recoverWithItem("kaboom")
uni.onFailure(t -> accept(t)).recoverWithItem("another boom")
| Constructor and Description |
|---|
UniOnFailure(Uni<T> upstream,
Predicate<? super Throwable> predicate) |
| Modifier and Type | Method and Description |
|---|---|
Uni<T> |
apply(Function<? super Throwable,? extends Throwable> mapper)
Deprecated.
|
Uni<T> |
invoke(Consumer<Throwable> callback)
|
Uni<T> |
invokeUni(Function<Throwable,? extends Uni<?>> action)
|
Uni<T> |
recoverWithItem(Function<? super Throwable,? extends T> function)
Recovers from the received failure (matching the predicate if set) by using a item generated by the given
function.
|
Uni<T> |
recoverWithItem(Supplier<T> supplier)
Recovers from the received failure (matching the predicate if set) by using a item generated by the given
supplier.
|
Uni<T> |
recoverWithItem(T fallback)
Recovers from the received failure (matching the predicate if set) by using a fallback item.
|
Uni<T> |
recoverWithUni(Function<? super Throwable,? extends Uni<? extends T>> function)
Recovers from the received failure (matching the predicate if set) with another
Uni. |
Uni<T> |
recoverWithUni(Supplier<? extends Uni<? extends T>> supplier)
Recovers from the received failure (matching the predicate if set) with another
Uni. |
Uni<T> |
recoverWithUni(Uni<? extends T> fallback)
Recovers from the received failure (matching the predicate if set) with another
Uni. |
UniRetry<T> |
retry()
Configures the retry strategy.
|
Uni<T> |
transform(Function<? super Throwable,? extends Throwable> mapper)
|
public Uni<T> invoke(Consumer<Throwable> callback)
Uni invoking the given callback when this Uni emits a failure (matching the
predicate if set).
If the callback throws an exception, a CompositeException is propagated downstream.
This exception is composed by the received failure and the thrown exception.
callback - the callback, must not be nullUnipublic Uni<T> invokeUni(Function<Throwable,? extends Uni<?>> action)
Uni invoking the given function when the current Uni propagates a failure
(matching the predicate if set). The function can transform the received failure into another exception that will
be fired as failure downstream.
Produces a new Uni invoking the given @{code action} when the failure event is received.
Unlike invoke(Consumer), the passed function returns a Uni. When the produced Uni sends
its item, this item is discarded, and the original failure is forwarded downstream. If the produced
Uni fails, a composite failure containing both the original failure and the failure from the executed
action is propagated downstream.
action - the callback, must not be nullUni@Deprecated public Uni<T> apply(Function<? super Throwable,? extends Throwable> mapper)
transform(Function)Uni invoking the given function when the current Uni propagates a failure. The
function can transform the received failure into another exception that will be fired as failure downstream.mapper - the mapper function, must not be null, must not return nullUnipublic Uni<T> transform(Function<? super Throwable,? extends Throwable> mapper)
Uni invoking the given function when the current Uni propagates a failure. The
function can transform the received failure into another exception that will be fired as failure downstream.mapper - the mapper function, must not be null, must not return nullUnipublic Uni<T> recoverWithItem(T fallback)
fallback - the fallback, can be nullUni that would emit the given fallback in case the upstream sends us a failure.public Uni<T> recoverWithItem(Supplier<T> supplier)
If the supplier throws an exception, a CompositeException containing both the received
failure and the thrown exception is propagated downstream.
supplier - the supplier providing the fallback item. Must not be null, can return null.Uni that would emit the produced item in case the upstream sends a failure.public Uni<T> recoverWithItem(Function<? super Throwable,? extends T> function)
If the function throws an exception, a CompositeException containing both the received
failure and the thrown exception is propagated downstream.
function - the function providing the fallback item. Must not be null, can return null.Uni that would emit the produced item in case the upstream sends a failure.public Uni<T> recoverWithUni(Function<? super Throwable,? extends Uni<? extends T>> function)
Uni. This uni is
produced by the given function. This uni can emit an item (potentially null or a failure. The
function must not return null.
If the function throws an exception, a CompositeException containing both the received
failure and the thrown exception is propagated downstream.
function - the function providing the fallback uni. Must not be null, must not return null.Uni that would emit events from the uni produced by the given function in case the
upstream sends a failure.public Uni<T> recoverWithUni(Supplier<? extends Uni<? extends T>> supplier)
Uni. This uni is
produced by the given supplier. This uni can emit an item (potentially null or a failure. The
supplier must not return null.
If the supplier throws an exception, a CompositeException containing both the received
failure and the thrown exception is propagated downstream.
supplier - the supplier providing the fallback uni. Must not be null, must not return null.Uni that would emits events from the uni produced by the given supplier in case the
upstream sends a failure.public Uni<T> recoverWithUni(Uni<? extends T> fallback)
Uni. This uni
can emit an item (potentially null or a failure.fallback - the fallbakc uni, must not be nullUni that would emit events from the uni in case the upstream sends a failure.Copyright © 2019–2020 SmallRye. All rights reserved.