Merge pull request #1735 from sumpfralle/olsr-jsoninfo-parser-handle-empty-result
[oweals/luci.git] / modules / luci-base / htdocs / luci-static / resources / luci.js
index af2b179ce3595870d88731af28700ae7a700a2ac..4e3c8445a94dc0013a20708e4744f622e7c9c951 100644 (file)
                },
 
                handleReadyStateChange: function(resolveFn, rejectFn, ev) {
-                       var xhr = this.xhr;
+                       var xhr = this.xhr,
+                           duration = Date.now() - this.start;
 
                        if (xhr.readyState !== 4)
                                return;
 
                        if (xhr.status === 0 && xhr.statusText === '') {
-                               rejectFn.call(this, new Error('XHR request aborted by browser'));
+                               if (duration >= this.timeout)
+                                       rejectFn.call(this, new Error('XHR request timed out'));
+                               else
+                                       rejectFn.call(this, new Error('XHR request aborted by browser'));
                        }
                        else {
                                var response = new Response(
-                                       xhr, xhr.responseURL || this.url, Date.now() - this.start);
+                                       xhr, xhr.responseURL || this.url, duration);
 
                                Promise.all(Request.interceptors.map(function(fn) { return fn(response) }))
                                        .then(resolveFn.bind(this, response))
                },
 
                probeSystemFeatures: function() {
+                       var sessionid = classes.rpc.getSessionID();
+
                        if (sysFeatures == null) {
                                try {
-                                       sysFeatures = JSON.parse(window.sessionStorage.getItem('sysFeatures'));
+                                       var data = JSON.parse(window.sessionStorage.getItem('sysFeatures'));
+
+                                       if (this.isObject(data) && this.isObject(data[sessionid]))
+                                               sysFeatures = data[sessionid];
                                }
                                catch (e) {}
                        }
                                        expect: { '': {} }
                                })().then(function(features) {
                                        try {
-                                               window.sessionStorage.setItem('sysFeatures', JSON.stringify(features));
+                                               var data = {};
+                                                   data[sessionid] = features;
+
+                                               window.sessionStorage.setItem('sysFeatures', JSON.stringify(data));
                                        }
                                        catch (e) {}