# Code coverage report for RxJS/dist/cjs/operators/catch.js

## Statements: 95.45% (42 / 44) Branches: 66.67% (12 / 18) Functions: 100% (10 / 10) Lines: 100% (36 / 36) Ignored: none

All files » RxJS/dist/cjs/operators/ » catch.js

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75

    1
    1

    2

    1

    12

    1

    1

    1

    1

    1

    1
    5
    5
    5
    5

    1
    1
    5

    5

    1
    7

    1

    1
    1

    1
    7

    7
    7
    7

    1
    7
    7
    1

    6

    1

    1'use strict';

    exports.__esModule = true;
    exports['default'] = _catch;

    function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }

    function _inherits(subClass, superClass) { Iif (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); Eif (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }

    function _classCallCheck(instance, Constructor) { Iif (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }

    var _Subscriber2 = require('../Subscriber');

    var _Subscriber3 = _interopRequireDefault(_Subscriber2);

    var _utilTryCatch = require('../util/tryCatch');

    var _utilTryCatch2 = _interopRequireDefault(_utilTryCatch);

    var _utilErrorObject = require('../util/errorObject');

    /**
     * Catches errors on the observable to be handled by returning a new observable or throwing an error.
     * @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.
     */

    function _catch(selector) {
        var catchOperator = new CatchOperator(selector);
        var caught = this.lift(catchOperator);
        catchOperator.caught = caught;
        return caught;
    }

    var CatchOperator = (function () {
        function CatchOperator(selector) {
            _classCallCheck(this, CatchOperator);

            this.selector = selector;
        }

        CatchOperator.prototype.call = function call(subscriber) {
            return new CatchSubscriber(subscriber, this.selector, this.caught);
        };

        return CatchOperator;
    })();

    var CatchSubscriber = (function (_Subscriber) {
        _inherits(CatchSubscriber, _Subscriber);

        function CatchSubscriber(destination, selector, caught) {
            _classCallCheck(this, CatchSubscriber);

            _Subscriber.call(this, destination);
            this.selector = selector;
            this.caught = caught;
        }

        CatchSubscriber.prototype._error = function _error(err) {
            var result = _utilTryCatch2['default'](this.selector)(err, this.caught);
            if (result === _utilErrorObject.errorObject) {
                this.destination.error(_utilErrorObject.errorObject.e);
            } else {
                this.add(result.subscribe(this.destination));
            }
        };

        return CatchSubscriber;
    })(_Subscriber3['default']);

    module.exports = exports['default'];