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SAAK,CAAC;YAChB,IAAI,CAAC;gBACH,MAAM,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;YAC3C,CAAE;YAAA,KAAK,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;gBACd,gBAAK,CAAC,KAAK,YAAC,IAAI,CAAC,CAAC;gBAClB,MAAM,CAAC;YACT,CAAC;YACD,IAAI,CAAC,sBAAsB,EAAE,CAAC;YAC9B,IAAI,CAAC,GAAG,CAAC,qCAAiB,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC;QAC5C,CAAC;IACH,CAAC;IACH,sBAAC;AAAD,CAAC,AAzBD,CAAoC,iCAAe,GAyBlD","sourcesContent":["import { Operator } from '../Operator';\nimport { Subscriber } from '../Subscriber';\nimport { Observable, ObservableInput } from '../Observable';\n\nimport { OuterSubscriber } from '../OuterSubscriber';\nimport { subscribeToResult } from '../util/subscribeToResult';\nimport { OperatorFunction } from '../interfaces';\n\n/**\n * Catches errors on the observable to be handled by returning a new observable or throwing an error.\n *\n * <img src=\"./img/catch.png\" width=\"100%\">\n *\n * @example <caption>Continues with a different Observable when there's an error</caption>\n *\n * Observable.of(1, 2, 3, 4, 5)\n * .map(n => {\n * \t if (n == 4) {\n * \t throw 'four!';\n * }\n *\t return n;\n * })\n * .catch(err => Observable.of('I', 'II', 'III', 'IV', 'V'))\n * .subscribe(x => console.log(x));\n * // 1, 2, 3, I, II, III, IV, V\n *\n * @example <caption>Retries the caught source Observable again in case of error, similar to retry() operator</caption>\n *\n * Observable.of(1, 2, 3, 4, 5)\n * .map(n => {\n * \t if (n === 4) {\n * \t throw 'four!';\n * }\n * \t return n;\n * })\n * .catch((err, caught) => caught)\n * .take(30)\n * .subscribe(x => console.log(x));\n * // 1, 2, 3, 1, 2, 3, ...\n *\n * @example <caption>Throws a new error when the source Observable throws an error</caption>\n *\n * Observable.of(1, 2, 3, 4, 5)\n * .map(n => {\n * if (n == 4) {\n * throw 'four!';\n * }\n * return n;\n * })\n * .catch(err => {\n * throw 'error in source. Details: ' + err;\n * })\n * .subscribe(\n * x => console.log(x),\n * err => console.log(err)\n * );\n * // 1, 2, 3, error in source. Details: four!\n *\n * @param {function} selector a function that takes as arguments `err`, which is the error, and `caught`, which\n * is the source observable, in case you'd like to \"retry\" that observable by returning it again. Whatever observable\n * is returned by the `selector` will be used to continue the observable chain.\n * @return {Observable} An observable that originates from either the source or the observable returned by the\n * catch `selector` function.\n * @name catchError\n */\nexport function catchError<T, R>(selector: (err: any, caught: Observable<T>) => ObservableInput<R>): OperatorFunction<T, T | R> {\n return function catchErrorOperatorFunction(source: Observable<T>): Observable<T | R> {\n const operator = new CatchOperator(selector);\n const caught = source.lift(operator);\n return (operator.caught = caught as Observable<T>);\n };\n}\n\nclass CatchOperator<T, R> implements Operator<T, T | R> {\n caught: Observable<T>;\n\n constructor(private selector: (err: any, caught: Observable<T>) => ObservableInput<T | R>) {\n }\n\n call(subscriber: Subscriber<R>, source: any): any {\n return source.subscribe(new CatchSubscriber(subscriber, this.selector, this.caught));\n }\n}\n\n/**\n * We need this JSDoc comment for affecting ESDoc.\n * @ignore\n * @extends {Ignored}\n */\nclass CatchSubscriber<T, R> extends OuterSubscriber<T, T | R> {\n constructor(destination: Subscriber<any>,\n private selector: (err: any, caught: Observable<T>) => ObservableInput<T | R>,\n private caught: Observable<T>) {\n super(destination);\n }\n\n // NOTE: overriding `error` instead of `_error` because we don't want\n // to have this flag this subscriber as `isStopped`. We can mimic the\n // behavior of the RetrySubscriber (from the `retry` operator), where\n // we unsubscribe from our source chain, reset our Subscriber flags,\n // then subscribe to the selector result.\n error(err: any) {\n if (!this.isStopped) {\n let result: any;\n try {\n result = this.selector(err, this.caught);\n } catch (err2) {\n super.error(err2);\n return;\n }\n this._unsubscribeAndRecycle();\n this.add(subscribeToResult(this, result));\n }\n }\n}\n"]}