UNPKG

wed

Version:

Wed is a schema-aware editor for XML documents.

55 lines (52 loc) 1.7 kB
define(function(require,exports,module){ import { OuterSubscriber } from '../OuterSubscriber'; import { subscribeToResult } from '../util/subscribeToResult'; export function catchError(selector) { return function catchErrorOperatorFunction(source) { const operator = new CatchOperator(selector); const caught = source.lift(operator); return (operator.caught = caught); }; } class CatchOperator { constructor(selector) { this.selector = selector; } call(subscriber, source) { return source.subscribe(new CatchSubscriber(subscriber, this.selector, this.caught)); } } /** * We need this JSDoc comment for affecting ESDoc. * @ignore * @extends {Ignored} */ class CatchSubscriber extends OuterSubscriber { constructor(destination, selector, caught) { super(destination); this.selector = selector; this.caught = caught; } // 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) { if (!this.isStopped) { let result; try { result = this.selector(err, this.caught); } catch (err2) { super.error(err2); return; } this._unsubscribeAndRecycle(); this.add(subscribeToResult(this, result)); } } } //# sourceMappingURL=catchError.js.map return module.exports; });