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

feat($http): flag timed out requests #11272

Closed
wants to merge 1 commit 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
18 changes: 13 additions & 5 deletions src/ng/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -1085,7 +1085,7 @@ function $HttpProvider() {
* - resolves the raw $http promise
* - calls $apply
*/
function done(status, response, headersString, statusText) {
function done(status, response, headersString, statusText, timedOut) {
if (cache) {
if (isSuccess(status)) {
cache.put(url, [status, response, parseHeaders(headersString), statusText]);
Expand All @@ -1096,7 +1096,7 @@ function $HttpProvider() {
}

function resolveHttpPromise() {
resolvePromise(response, status, headersString, statusText);
resolvePromise(response, status, headersString, statusText, timedOut);
}

if (useApplyAsync) {
Expand All @@ -1111,17 +1111,25 @@ function $HttpProvider() {
/**
* Resolves the raw $http promise.
*/
function resolvePromise(response, status, headers, statusText) {
function resolvePromise(response, status, headers, statusText, timedOut) {
// normalize internal statuses to 0
status = Math.max(status, 0);

(isSuccess(status) ? deferred.resolve : deferred.reject)({
var result = {
data: response,
status: status,
headers: headersGetter(headers),
config: config,
statusText: statusText
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not just add timeOut: timeOut here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't want to alter the current success result, since it logically can never be a timeout (hence timeOut: false would be redundant; I think of timeOut as a possible outcome of an error result). But maybe it'd better to add timeOut: [true | false] every time.

Another question: would you go with timedOut, timeOut, or timeout?

});
};
if (isSuccess(status)) {
deferred.resolve(result);
} else {
if (timedOut) {
result.timedOut = true;
}
deferred.reject(result);
}
}

function resolvePromiseWithResult(result) {
Expand Down
4 changes: 3 additions & 1 deletion src/ng/httpBackend.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,9 @@ function createHttpBackend($browser, createXhr, $browserDefer, callbacks, rawDoc
}


var timedOut;
function timeoutRequest() {
timedOut = true;
jsonpDone && jsonpDone();
xhr && xhr.abort();
}
Expand All @@ -131,7 +133,7 @@ function createHttpBackend($browser, createXhr, $browserDefer, callbacks, rawDoc
}
jsonpDone = xhr = null;

callback(status, response, headersString, statusText);
callback(status, response, headersString, statusText, timedOut);
$browser.$$completeOutstandingRequest(noop);
}
};
Expand Down