From 893c061dd60feb6daf31ab18dc0675ca39752c29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rog=C3=A9rio=20Chaves?= Date: Fri, 5 Feb 2016 16:26:58 -0200 Subject: [PATCH 1/2] Handle timeout on XHR requests --- lib/adapters/xhr.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/adapters/xhr.js b/lib/adapters/xhr.js index c930f2e..7eaa33a 100644 --- a/lib/adapters/xhr.js +++ b/lib/adapters/xhr.js @@ -76,6 +76,14 @@ module.exports = function xhrAdapter(resolve, reject, config) { request = null; }; + // Handle timeout + request.ontimeout = function handleTimeout() { + reject(new Error('Timeout')); + + // Clean up request + request = null; + }; + // Add xsrf header // This is only done if running in a standard browser environment. // Specifically not if we're in a web worker, or react-native. From ed4a4dc9a930c517b86bced08ed63393dcdfa8cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rog=C3=A9rio=20Chaves?= Date: Wed, 2 Mar 2016 15:16:01 -0300 Subject: [PATCH 2/2] Uses the same timeout error message on XHR adapter than HTTP adapter --- lib/adapters/xhr.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/adapters/xhr.js b/lib/adapters/xhr.js index 7eaa33a..16a435f 100644 --- a/lib/adapters/xhr.js +++ b/lib/adapters/xhr.js @@ -78,7 +78,10 @@ module.exports = function xhrAdapter(resolve, reject, config) { // Handle timeout request.ontimeout = function handleTimeout() { - reject(new Error('Timeout')); + var err = new Error('timeout of ' + config.timeout + 'ms exceeded'); + err.timeout = config.timeout; + err.code = 'ECONNABORTED'; + reject(err); // Clean up request request = null;