onErrorResume method

Stream<T> onErrorResume(
  1. Stream<T> recoveryFn(
    1. Object error,
    2. StackTrace stackTrace
    )
)

Intercepts error events and switches to a recovery stream created by the provided recoveryFn.

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

The recoveryFn receives the emitted error and returns a Stream. You can perform logic in the recoveryFn to return different Streams 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 onErrorResumeNext or onErrorReturn.

Example

ErrorStream(Exception())
  .onErrorResume((e, st) =>
      Stream.fromIterable([e is StateError ? 1 : 0]))
  .listen(print); // prints 0

Implementation

Stream<T> onErrorResume(
        Stream<T> Function(Object error, StackTrace stackTrace) recoveryFn) =>
    OnErrorResumeStreamTransformer<T>(recoveryFn).bind(this);