Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

fix($resource): Check if timeoutDeferred is null inside $cancelRequest #16037

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/ngResource/resource.js
Original file line number Diff line number Diff line change
Expand Up @@ -823,7 +823,9 @@ angular.module('ngResource', ['ng']).

function cancelRequest(value) {
promise.catch(noop);
timeoutDeferred.resolve(value);
if (timeoutDeferred !== null) {
timeoutDeferred.resolve(value);
}
}
};

Expand Down
19 changes: 19 additions & 0 deletions test/ngResource/resourceSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2101,6 +2101,25 @@ describe('cancelling requests', function() {

expect(creditCard.$cancelRequest).toBe(noop);
});

it('should not break when calling old `$cancelRequest` after the response arrives', function() {
$httpBackend.whenGET('/CreditCard').respond({});

var CreditCard = $resource('/CreditCard', {}, {
get: {
method: 'GET',
cancellable: true
}
});

var creditCard = CreditCard.get();
var cancelRequest = creditCard.$cancelRequest;

$httpBackend.flush();

expect(cancelRequest).not.toBe(noop);
expect(cancelRequest).not.toThrow();
});
});

describe('configuring `cancellable` on the provider', function() {
Expand Down