diff --git a/src/ng/http.js b/src/ng/http.js index 95a33ae7a1fb..cb087728a25b 100644 --- a/src/ng/http.js +++ b/src/ng/http.js @@ -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]); @@ -1096,7 +1096,7 @@ function $HttpProvider() { } function resolveHttpPromise() { - resolvePromise(response, status, headersString, statusText); + resolvePromise(response, status, headersString, statusText, timedOut); } if (useApplyAsync) { @@ -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 - }); + }; + if (isSuccess(status)) { + deferred.resolve(result); + } else { + if (timedOut) { + result.timedOut = true; + } + deferred.reject(result); + } } function resolvePromiseWithResult(result) { diff --git a/src/ng/httpBackend.js b/src/ng/httpBackend.js index 5ba78b749932..652a4ffb9652 100644 --- a/src/ng/httpBackend.js +++ b/src/ng/httpBackend.js @@ -119,7 +119,9 @@ function createHttpBackend($browser, createXhr, $browserDefer, callbacks, rawDoc } + var timedOut; function timeoutRequest() { + timedOut = true; jsonpDone && jsonpDone(); xhr && xhr.abort(); } @@ -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); } };