Class UniOnFailure<T,E extends Throwable>
- Type Parameters:
T- the type of itemE- the type of failure
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionrecoverWithItem(Function<E, ? extends T> function) Recovers from the received failure (matching the predicate if set) by using a item generated by the given function.recoverWithItem(Supplier<T> supplier) Recovers from the received failure (matching the predicate if set) by using a item generated by the given supplier.recoverWithItem(T fallback) Recovers from the received failure (matching the predicate if set) by using a fallback item.Recovers from the received failure by ignoring it and emitting anullitem in the resultingUni.recoverWithUni(Uni<? extends T> fallback) Recovers from the received failure (matching the predicate if set) with anotherUni.recoverWithUni(Function<E, Uni<? extends T>> function) Recovers from the received failure (matching the predicate if set) with anotherUni.recoverWithUni(Supplier<Uni<? extends T>> supplier) Recovers from the received failure (matching the predicate if set) with anotherUni.retry()Configures the retry strategy.
-
Constructor Details
-
UniOnFailure
-
-
Method Details
-
invoke
Produces a newUniinvoking the given callback when thisUniemits a failure (matching the predicate if set).If the callback throws an exception, a
CompositeExceptionis propagated downstream. This exception is composed by the received failure and the thrown exception.- Parameters:
callback- the callback, must not benull- Returns:
- the new
Uni
-
invoke
Produces a newUniinvoking the given callback when thisUniemits a failure (matching the predicate if set).If the callback throws an exception, a
CompositeExceptionis propagated downstream. This exception is composed by the received failure and the thrown exception.- Parameters:
callback- the callback, must not benull- Returns:
- the new
Uni
-
call
Produces a newUniinvoking the given function when the currentUnipropagates 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
Uniinvoking the given @{code action} when thefailureevent is received.Unlike
invoke(Consumer), the passed function returns aUni. When the producedUnisends its item, this item is discarded, and the originalfailureis forwarded downstream. If the producedUnifails, a composite failure containing both the original failure and the failure from the executed action is propagated downstream.- Parameters:
action- the callback, must not benull- Returns:
- the new
Uni
-
call
Produces a newUniinvoking the given supplier when the currentUnipropagates a failure (matching the predicate if set). The supplier ignores the failure.Produces a new
Uniinvoking the given @{code supplier} when thefailureevent is received.Unlike
invoke(Consumer), the passed function returns aUni. When the producedUnisends its item, this item is discarded, and the originalfailureis forwarded downstream. If the producedUnifails, a composite failure containing both the original failure and the failure from the executed supplier is propagated downstream.- Parameters:
supplier- the supplier, must not benull- Returns:
- the new
Uni
-
transform
Produces a newUniinvoking the given function when the currentUnipropagates a failure. The function can transform the received failure into another exception that will be fired as failure downstream.- Parameters:
mapper- the mapper function, must not benull, must not returnnull- Returns:
- the new
Uni
-
recoverWithItem
Recovers from the received failure (matching the predicate if set) by using a fallback item.- Parameters:
fallback- the fallback, can benull- Returns:
- the new
Unithat would emit the given fallback in case the upstream sends us a failure.
-
recoverWithItem
Recovers from the received failure (matching the predicate if set) by using a item generated by the given supplier. The supplier is called when the failure is received.If the supplier throws an exception, a
CompositeExceptioncontaining both the received failure and the thrown exception is propagated downstream.- Parameters:
supplier- the supplier providing the fallback item. Must not benull, can returnnull.- Returns:
- the new
Unithat would emit the produced item in case the upstream sends a failure.
-
recoverWithItem
Recovers from the received failure (matching the predicate if set) by using a item generated by the given function. The function is called when the failure is received.If the function throws an exception, a
CompositeExceptioncontaining both the received failure and the thrown exception is propagated downstream.- Parameters:
function- the function providing the fallback item. Must not benull, can returnnull.- Returns:
- the new
Unithat would emit the produced item in case the upstream sends a failure.
-
recoverWithUni
Recovers from the received failure (matching the predicate if set) with anotherUni. Thisuniis produced by the given function. Thisunican emit an item (potentiallynullor a failure. The function must not returnnull.If the function throws an exception, a
CompositeExceptioncontaining both the received failure and the thrown exception is propagated downstream.- Parameters:
function- the function providing the fallback uni. Must not benull, must not returnnull.- Returns:
- the new
Unithat would emit events from the uni produced by the given function in case the upstream sends a failure.
-
recoverWithUni
Recovers from the received failure (matching the predicate if set) with anotherUni. Thisuniis produced by the given supplier. Thisunican emit an item (potentiallynullor a failure. The supplier must not returnnull.If the supplier throws an exception, a
CompositeExceptioncontaining both the received failure and the thrown exception is propagated downstream.- Parameters:
supplier- the supplier providing the fallback uni. Must not benull, must not returnnull.- Returns:
- the new
Unithat would emits events from the uni produced by the given supplier in case the upstream sends a failure.
-
recoverWithUni
Recovers from the received failure (matching the predicate if set) with anotherUni. Thisunican emit an item (potentiallynullor a failure.- Parameters:
fallback- the fallbakc uni, must not benull- Returns:
- the new
Unithat would emit events from the uni in case the upstream sends a failure.
-
retry
Configures the retry strategy.- Returns:
- the object to configure the retry.
-
recoverWithNull
Recovers from the received failure by ignoring it and emitting anullitem in the resultingUni.- Returns:
- the new
Unithat emitsnullon failure
-