This repository was archived by the owner on Apr 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27.4k
feat($http,$resource): statusText resolved in timeout promise #14021
Closed
Closed
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -658,7 +658,9 @@ angular.module('ngResource', ['ng']). | |
httpConfig.timeout = timeoutDeferred.promise; | ||
|
||
if (numericTimeout) { | ||
numericTimeoutPromise = $timeout(timeoutDeferred.resolve, numericTimeout); | ||
numericTimeoutPromise = $timeout(function() { | ||
timeoutDeferred.resolve("timeout"); | ||
}, numericTimeout); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This can be also written as: numericTimeoutPromise = $timeout(timeoutDeferred.resolve, numericTimeout, false, 'timeout');
// OR
numericTimeoutPromise = $timeout(timeoutDeferred.resolve.bind(null, 'timeout'), numericTimeout);
// OR
numericTimeoutPromise = $timeout(angular.bind(timeoutDeferred, timeoutDeferred.resolve, 'timeout'), numericTimeout); There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But...you know...it's better to stay as is 😥 |
||
} | ||
} | ||
|
||
|
@@ -729,7 +731,12 @@ angular.module('ngResource', ['ng']). | |
// - return the instance / collection | ||
value.$promise = promise; | ||
value.$resolved = false; | ||
if (cancellable) value.$cancelRequest = timeoutDeferred.resolve; | ||
|
||
if (cancellable) { | ||
value.$cancelRequest = function() { | ||
timeoutDeferred.resolve("cancelled"); | ||
}; | ||
} | ||
|
||
return value; | ||
} | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1544,7 +1544,13 @@ describe('cancelling requests', function() { | |
} | ||
}); | ||
|
||
CreditCard.get(); | ||
var creditCard = CreditCard.get(); | ||
|
||
creditCard.$promise.catch(function(err) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be better to also verify that the function has been called (e.g. by using a spy). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thnx. I pushed a fix |
||
expect(err.status).toEqual(-1); | ||
expect(err.statusText).toEqual("timeout"); | ||
}); | ||
|
||
$timeout.flush(); | ||
expect($httpBackend.flush).toThrow(new Error('No pending request to flush !')); | ||
|
||
|
@@ -1563,7 +1569,14 @@ describe('cancelling requests', function() { | |
} | ||
}); | ||
|
||
CreditCard.get().$cancelRequest(); | ||
var creditCard = CreditCard.get(); | ||
|
||
creditCard.$promise.catch(function(err) { | ||
expect(err.status).toEqual(-1); | ||
expect(err.statusText).toEqual("cancelled"); | ||
}); | ||
|
||
creditCard.$cancelRequest(); | ||
expect($httpBackend.flush).toThrow(new Error('No pending request to flush !')); | ||
|
||
CreditCard.get(); | ||
|
@@ -1581,7 +1594,14 @@ describe('cancelling requests', function() { | |
} | ||
}); | ||
|
||
CreditCard.get().$cancelRequest(); | ||
var creditCard = CreditCard.get(); | ||
|
||
creditCard.$promise.catch(function(err) { | ||
expect(err.status).toEqual(-1); | ||
expect(err.statusText).toEqual("cancelled"); | ||
}); | ||
|
||
creditCard.$cancelRequest(); | ||
expect($httpBackend.flush).toThrow(new Error('No pending request to flush !')); | ||
|
||
CreditCard.get(); | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not just always call
callback(-1, undefined, '', statusText)
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because some unit tests use spy's
toHaveBeenCalledWith()
method which is strict regarding the number of parameters, and I didn't want to break the old API. Withundefined
as the forth parameter those tests will fail, so may be some third-party modules would break if they test for it. It's minor however, and if you agree, we can just change it.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The advice in the docs is that "you should never need to use this service directly" and it's use as a function isn't even documented (even more so the arguments of the
done
callback).I really think it's a non-issue, so go ahead and use the simpler version 😄