From 8c4000f2d1ac45cebff45a0e48abab4e64f8e62c Mon Sep 17 00:00:00 2001 From: Aakash Chaudhary Date: Wed, 18 Jan 2017 20:12:33 +0530 Subject: [PATCH 1/2] Set request timeout response status --- src/ng/httpBackend.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/ng/httpBackend.js b/src/ng/httpBackend.js index 501c1de86c73..d8e291e4e315 100644 --- a/src/ng/httpBackend.js +++ b/src/ng/httpBackend.js @@ -108,9 +108,14 @@ function createHttpBackend($browser, createXhr, $browserDefer, callbacks, rawDoc completeRequest(callback, -1, null, null, ''); }; + var requestTimeout = function() { + // Set standard request timeout status code: 408 + completeRequest(callback, 408, null, null, ''); + }; + xhr.onerror = requestError; xhr.onabort = requestError; - xhr.ontimeout = requestError; + xhr.ontimeout = requestTimeout; forEach(eventHandlers, function(value, key) { xhr.addEventListener(key, value); From f77cb48fc5ac63a9479d3f5692b7db45f709f844 Mon Sep 17 00:00:00 2001 From: Aakash Chaudhary Date: Wed, 18 Jan 2017 20:15:42 +0530 Subject: [PATCH 2/2] Updating test case for timed out requests --- test/ng/httpBackendSpec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/ng/httpBackendSpec.js b/test/ng/httpBackendSpec.js index fbc58072894f..297fa75b58b3 100644 --- a/test/ng/httpBackendSpec.js +++ b/test/ng/httpBackendSpec.js @@ -175,7 +175,7 @@ describe('$httpBackend', function() { it('should complete the request on timeout', function() { callback.and.callFake(function(status, response, headers, statusText) { - expect(status).toBe(-1); + expect(status).toBe(408); expect(response).toBe(null); expect(headers).toBe(null); expect(statusText).toBe('');