onErrorResumeSingle method

Single<T> onErrorResumeSingle(
  1. Single<T> fallbackSupplier(
    1. Object error,
    2. StackTrace stackTrace
    )
)

Intercepts error events and switches to a recovery Single created by the provided fallbackSupplier.

The onErrorResumeSingle operator intercepts an onError notification from the source Stream. Instead of passing the error through to any listeners, it replaces it with another Single created by the fallbackSupplier.

The fallbackSupplier receives the emitted error and returns a Single. You can perform logic in the fallbackSupplier to return different Singles based on the type of error that was emitted.

If you do not need to perform logic based on the type of error that was emitted, please consider using onErrorResumeNextSingle or onErrorReturn.

Example

Single<int>.error(Exception())
    .onErrorResumeSingle((e, st) => Single.value(e is StateError ? 1 : 0))
    .listen(print); // prints 0

Implementation

Single<T> onErrorResumeSingle(
        Single<T> Function(Object error, StackTrace stackTrace)
            fallbackSupplier) =>
    forwardSingleWithSink(
        () => _OnErrorResumeSingleSingleSink(fallbackSupplier));