Options
All
  • Public
  • Public/Protected
  • All
Menu

Module "operators/catch-if"

Index

Functions

Functions

catchIf

  • catchIf<T, O>(conditionFn: (error: any) => boolean, selectorFn: (error: any) => O): OperatorFunction<T, T | ObservedValueOf<O>>
  • Catches an error if [conditionFn] evaluates to be truthy. If the error is catched, the original observable sequence will be replaced with the result of [selectorFn].

    example
    // Example with condition evaluating to `true`:
    const source =      cold('v#');
    const replacement = cold('r|');
    
    const expected =    cold('vr|');
    
    const result = source.pipe(
      catchIf(
        () => true,
        () => replacement
      )
    );
    
    // Example with condition evaluating to `false`:
    const source =      cold('v#');
    const replacement = cold('r|');
    
    const expected =    cold('v#');
    
    const result = source.pipe(
      catchIf(
        () => false,
        () => replacement
      )
    );
    

    Type parameters

    • T

    • O: ObservableInput<any>

    Parameters

    • conditionFn: (error: any) => boolean

      Determines if an error should be catched.

        • (error: any): boolean
        • Parameters

          • error: any

          Returns boolean

    • selectorFn: (error: any) => O

      Selector which provides a new observable. The newly provided observable will continue the observable chain.

        • (error: any): O
        • Parameters

          • error: any

          Returns O

    Returns OperatorFunction<T, T | ObservedValueOf<O>>

Generated using TypeDoc