Commit 9c829e37 authored by analog-nico's avatar analog-nico
Browse files

Fix for errors emitted by request

parent 3a21f12e
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -52,6 +52,11 @@ function ownCallback(err, httpResponse, body) {
        throw thrownException;
    }

    // Mimic original behavior of errors emitted by request with no error listener registered
    if (err && self._rp_then_invoked !== true && self.listeners('error').length === 1) {
        throw err;
    }

}

var originalInit = request.Request.prototype.init;
@@ -86,6 +91,7 @@ request.Request.prototype.init = function (options) {
};

request.Request.prototype.then = function (onFulfilled, onRejected) {
    this._rp_then_invoked = true;
    return this._rp_promise.then(onFulfilled, onRejected);
};

+10 −0
Original line number Diff line number Diff line
@@ -568,4 +568,14 @@ describe('Request-Promise', function () {

    });

    describe("should not alter Request's original behavior", function () {

        it('like emitting errors with no listener', function () {
            expect(function () {
                rp({});
            }).to.throw();
        });

    });

});