luci-base: luci.js: improve XHR issue diagnostics
authorJo-Philipp Wich <jo@mein.io>
Sat, 21 Sep 2019 08:19:22 +0000 (10:19 +0200)
committerJo-Philipp Wich <jo@mein.io>
Sat, 21 Sep 2019 08:23:37 +0000 (10:23 +0200)
Differentiate between request timeouts and other error reasons.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
modules/luci-base/htdocs/luci-static/resources/luci.js

index af2b179ce3595870d88731af28700ae7a700a2ac..1d349ebc1735e26278a489fd846c6d39b1e7f95c 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))