PATH:
usr
/
local
/
lib
/
node_modules
/
ghost-cli
/
node_modules
/
rxjs
/
src
/
internal
/
operators
import { Operator } from '../Operator'; import { Subscriber } from '../Subscriber'; import { Observable } from '../Observable'; import { OuterSubscriber } from '../OuterSubscriber'; import { InnerSubscriber } from '../InnerSubscriber'; import { subscribeToResult } from '../util/subscribeToResult'; import { ObservableInput, OperatorFunction, ObservedValueOf } from '../types'; /* tslint:disable:max-line-length */ export function catchError<T, O extends ObservableInput<any>>(selector: (err: any, caught: Observable<T>) => O): OperatorFunction<T, T | ObservedValueOf<O>>; /* tslint:enable:max-line-length */ /** * Catches errors on the observable to be handled by returning a new observable or throwing an error. * *  * * ## Examples * Continues with a different Observable when there's an error * * ```ts * import { of } from 'rxjs'; * import { map, catchError } from 'rxjs/operators'; * * of(1, 2, 3, 4, 5).pipe( * map(n => { * if (n === 4) { * throw 'four!'; * } * return n; * }), * catchError(err => of('I', 'II', 'III', 'IV', 'V')), * ) * .subscribe(x => console.log(x)); * // 1, 2, 3, I, II, III, IV, V * ``` * * Retries the caught source Observable again in case of error, similar to retry() operator * * ```ts * import { of } from 'rxjs'; * import { map, catchError, take } from 'rxjs/operators'; * * of(1, 2, 3, 4, 5).pipe( * map(n => { * if (n === 4) { * throw 'four!'; * } * return n; * }), * catchError((err, caught) => caught), * take(30), * ) * .subscribe(x => console.log(x)); * // 1, 2, 3, 1, 2, 3, ... * ``` * * Throws a new error when the source Observable throws an error * * ```ts * import { of } from 'rxjs'; * import { map, catchError } from 'rxjs/operators'; * * of(1, 2, 3, 4, 5).pipe( * map(n => { * if (n === 4) { * throw 'four!'; * } * return n; * }), * catchError(err => { * throw 'error in source. Details: ' + err; * }), * ) * .subscribe( * x => console.log(x), * err => console.log(err) * ); * // 1, 2, 3, error in source. Details: four! * ``` * * @param {function} selector a function that takes as arguments `err`, which is the error, and `caught`, which * is the source observable, in case you'd like to "retry" that observable by returning it again. Whatever observable * is returned by the `selector` will be used to continue the observable chain. * @return {Observable} An observable that originates from either the source or the observable returned by the * catch `selector` function. * @name catchError */ export function catchError<T, O extends ObservableInput<any>>( selector: (err: any, caught: Observable<T>) => O ): OperatorFunction<T, T | ObservedValueOf<O>> { return function catchErrorOperatorFunction(source: Observable<T>): Observable<T | ObservedValueOf<O>> { const operator = new CatchOperator(selector); const caught = source.lift(operator); return (operator.caught = caught as Observable<T>); }; } class CatchOperator<T, R> implements Operator<T, T | R> { caught: Observable<T>; constructor(private selector: (err: any, caught: Observable<T>) => ObservableInput<T | R>) { } call(subscriber: Subscriber<R>, source: any): any { return source.subscribe(new CatchSubscriber(subscriber, this.selector, this.caught)); } } /** * We need this JSDoc comment for affecting ESDoc. * @ignore * @extends {Ignored} */ class CatchSubscriber<T, R> extends OuterSubscriber<T, T | R> { constructor(destination: Subscriber<any>, private selector: (err: any, caught: Observable<T>) => ObservableInput<T | R>, private caught: Observable<T>) { super(destination); } // NOTE: overriding `error` instead of `_error` because we don't want // to have this flag this subscriber as `isStopped`. We can mimic the // behavior of the RetrySubscriber (from the `retry` operator), where // we unsubscribe from our source chain, reset our Subscriber flags, // then subscribe to the selector result. error(err: any) { if (!this.isStopped) { let result: any; try { result = this.selector(err, this.caught); } catch (err2) { super.error(err2); return; } this._unsubscribeAndRecycle(); const innerSubscriber = new InnerSubscriber(this, undefined, undefined); this.add(innerSubscriber); subscribeToResult(this, result, undefined, undefined, innerSubscriber); } } }
[-] toArray.ts
[edit]
[-] window.ts
[edit]
[-] retry.ts
[edit]
[-] mergeAll.ts
[edit]
[-] windowWhen.ts
[edit]
[-] every.ts
[edit]
[-] timeout.ts
[edit]
[-] debounceTime.ts
[edit]
[-] index.ts
[edit]
[-] takeWhile.ts
[edit]
[-] audit.ts
[edit]
[-] reduce.ts
[edit]
[-] mapTo.ts
[edit]
[-] count.ts
[edit]
[-] debounce.ts
[edit]
[-] throwIfEmpty.ts
[edit]
[-] auditTime.ts
[edit]
[-] scan.ts
[edit]
[-] switchAll.ts
[edit]
[-] map.ts
[edit]
[-] bufferCount.ts
[edit]
[-] mergeScan.ts
[edit]
[-] publish.ts
[edit]
[-] min.ts
[edit]
[+]
..
[-] publishReplay.ts
[edit]
[-] bufferTime.ts
[edit]
[-] share.ts
[edit]
[-] repeat.ts
[edit]
[-] distinct.ts
[edit]
[-] concatMapTo.ts
[edit]
[-] buffer.ts
[edit]
[-] concatMap.ts
[edit]
[-] max.ts
[edit]
[-] partition.ts
[edit]
[-] observeOn.ts
[edit]
[-] bufferWhen.ts
[edit]
[-] dematerialize.ts
[edit]
[-] throttle.ts
[edit]
[-] groupBy.ts
[edit]
[-] withLatestFrom.ts
[edit]
[-] exhaust.ts
[edit]
[-] exhaustMap.ts
[edit]
[-] retryWhen.ts
[edit]
[-] zipAll.ts
[edit]
[-] find.ts
[edit]
[-] mergeMap.ts
[edit]
[-] single.ts
[edit]
[-] last.ts
[edit]
[-] combineLatest.ts
[edit]
[-] publishLast.ts
[edit]
[-] pluck.ts
[edit]
[-] pairwise.ts
[edit]
[-] distinctUntilChanged.ts
[edit]
[-] timeInterval.ts
[edit]
[-] shareReplay.ts
[edit]
[-] skipUntil.ts
[edit]
[-] findIndex.ts
[edit]
[-] windowToggle.ts
[edit]
[-] startWith.ts
[edit]
[-] timeoutWith.ts
[edit]
[-] concat.ts
[edit]
[-] materialize.ts
[edit]
[-] timestamp.ts
[edit]
[-] onErrorResumeNext.ts
[edit]
[-] subscribeOn.ts
[edit]
[-] takeUntil.ts
[edit]
[-] skipLast.ts
[edit]
[-] throttleTime.ts
[edit]
[-] mergeMapTo.ts
[edit]
[-] multicast.ts
[edit]
[-] merge.ts
[edit]
[-] takeLast.ts
[edit]
[-] delayWhen.ts
[edit]
[-] sampleTime.ts
[edit]
[-] tap.ts
[edit]
[-] take.ts
[edit]
[-] sample.ts
[edit]
[-] filter.ts
[edit]
[-] skip.ts
[edit]
[-] expand.ts
[edit]
[-] publishBehavior.ts
[edit]
[-] sequenceEqual.ts
[edit]
[-] ignoreElements.ts
[edit]
[-] catchError.ts
[edit]
[-] endWith.ts
[edit]
[-] refCount.ts
[edit]
[-] windowCount.ts
[edit]
[-] defaultIfEmpty.ts
[edit]
[-] windowTime.ts
[edit]
[-] switchMapTo.ts
[edit]
[-] switchMap.ts
[edit]
[-] delay.ts
[edit]
[-] bufferToggle.ts
[edit]
[-] repeatWhen.ts
[edit]
[-] concatAll.ts
[edit]
[-] first.ts
[edit]
[-] zip.ts
[edit]
[-] elementAt.ts
[edit]
[-] skipWhile.ts
[edit]
[-] race.ts
[edit]
[-] finalize.ts
[edit]
[-] combineAll.ts
[edit]
[-] distinctUntilKeyChanged.ts
[edit]
[-] isEmpty.ts
[edit]