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] 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.