diff --git a/src/main/java/io/reactivex/rxjava3/core/Completable.java b/src/main/java/io/reactivex/rxjava3/core/Completable.java index 0913ac398d..4a5bd55c39 100644 --- a/src/main/java/io/reactivex/rxjava3/core/Completable.java +++ b/src/main/java/io/reactivex/rxjava3/core/Completable.java @@ -2086,6 +2086,33 @@ public final Completable onErrorResumeNext(@NonNull Function + * + *

+ * You can use this to prevent errors from propagating or to supply fallback data should errors be + * encountered. + *

+ *
Scheduler:
+ *
{@code onErrorResumeWith} does not operate by default on a particular {@link Scheduler}.
+ *
+ * + * @param fallback + * the next {@code CompletableSource} that will take over if the current {@code Completable} encounters + * an error + * @return the new {@code Completable} instance + * @throws NullPointerException if {@code fallback} is {@code null} + * @see ReactiveX operators documentation: Catch + */ + @CheckReturnValue + @NonNull + @SchedulerSupport(SchedulerSupport.NONE) + public final Completable onErrorResumeWith(@NonNull CompletableSource fallback) { + Objects.requireNonNull(fallback, "fallback is null"); + return onErrorResumeNext(Functions.justFunction(fallback)); + } /** * Nulls out references to the upstream producer and downstream {@link CompletableObserver} if diff --git a/src/main/java/io/reactivex/rxjava3/core/Maybe.java b/src/main/java/io/reactivex/rxjava3/core/Maybe.java index 1d385ce148..7bdfe05ee5 100644 --- a/src/main/java/io/reactivex/rxjava3/core/Maybe.java +++ b/src/main/java/io/reactivex/rxjava3/core/Maybe.java @@ -4084,7 +4084,7 @@ public final Maybe onErrorComplete(@NonNull Predicate pred * Resumes the flow with the given {@link MaybeSource} when the current {@code Maybe} fails instead of * signaling the error via {@code onError}. *

- * + * *

* You can use this to prevent errors from propagating or to supply fallback data should errors be * encountered. @@ -4112,7 +4112,7 @@ public final Maybe onErrorResumeWith(@NonNull MaybeSource fallba * Resumes the flow with a {@link MaybeSource} returned for the failure {@link Throwable} of the current {@code Maybe} by a * function instead of signaling the error via {@code onError}. *

- * + * *

* You can use this to prevent errors from propagating or to supply fallback data should errors be * encountered. diff --git a/src/test/java/io/reactivex/rxjava3/internal/operators/completable/CompletableResumeNextTest.java b/src/test/java/io/reactivex/rxjava3/internal/operators/completable/CompletableResumeNextTest.java index 5670264378..fb5390cdcc 100644 --- a/src/test/java/io/reactivex/rxjava3/internal/operators/completable/CompletableResumeNextTest.java +++ b/src/test/java/io/reactivex/rxjava3/internal/operators/completable/CompletableResumeNextTest.java @@ -13,18 +13,19 @@ package io.reactivex.rxjava3.internal.operators.completable; +import static org.mockito.Mockito.*; import org.junit.Test; import io.reactivex.rxjava3.core.*; import io.reactivex.rxjava3.exceptions.TestException; -import io.reactivex.rxjava3.functions.Function; +import io.reactivex.rxjava3.functions.*; import io.reactivex.rxjava3.internal.functions.Functions; import io.reactivex.rxjava3.testsupport.TestHelper; public class CompletableResumeNextTest extends RxJavaTest { @Test - public void resumeWithError() { + public void resumeNextError() { Completable.error(new TestException()) .onErrorResumeNext(Functions.justFunction(Completable.error(new TestException("second")))) .to(TestHelper.testConsumer()) @@ -58,4 +59,28 @@ public void disposed() { .onErrorResumeNext(Functions.justFunction(Completable.never())) ); } + + @Test + public void resumeWithNoError() throws Throwable { + Action action = mock(Action.class); + + Completable.complete() + .onErrorResumeWith(Completable.fromAction(action)) + .test() + .assertResult(); + + verify(action, never()).run(); + } + + @Test + public void resumeWithError() throws Throwable { + Action action = mock(Action.class); + + Completable.error(new TestException()) + .onErrorResumeWith(Completable.fromAction(action)) + .test() + .assertResult(); + + verify(action).run(); + } }