-
Notifications
You must be signed in to change notification settings - Fork 27.4k
feat($http,$resource): statusText resolved in timeout promise #14021
Conversation
Timeout-promise resolved-value will be passed as response error statusText ```js $http({ method: 'GET', url: '...', timeout: $timeout(function() { return "something"; }, 500) }).catch(function(err) { console.log(err.statusText); // something }); ``` This feature will also help distinguish cancelled $resource requests from timed-out $resource requests. Before both cases resulted with the same error object: ```{status: -1, statusText: '', ...}``` and were not giving much options to handle them in different way. Now cancelled requests will come with statusText='cancelled' and timed-out requests with statusText='timeout' in error object.
for (var i = 0, ii = responses.length; i < ii; i++) { | ||
if (responses[i] === handleResponse) { | ||
responses.splice(i, 1); | ||
callback(-1, undefined, ''); | ||
if (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.
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. With undefined
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 😄
Overall looks good. I left a couple of comments. |
@mrac , you never pinged me and I missed your latest change. |
Is this a BC? The statusText is now something that it wasn't before in some cases. Could break some logic / tests. |
In that sense it can be thought of as a BC, I guess. |
We have added the xhrStatus to the response in the 1.6.x branch. |
@Narretz @gkalpak |
Timeout-promise resolved value will be passed as response error statusText.
This feature will also help distinguish cancelled $resource requests
from timed-out $resource requests. Before, both cases resulted
with the same error object:
{status: -1, statusText: '', ...}
thus impossible to handle both cases in different way.
Now cancelled requests will come with statusText='cancelled',
and timed-out requests with statusText='timeout' in the error object.