luci-base: luci.js: improve XHR issue diagnostics
Differentiate between request timeouts and other error reasons. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
This commit is contained in:
parent
d24fa4ad61
commit
afeacdc7df
1 changed files with 7 additions and 3 deletions
|
@ -399,17 +399,21 @@
|
||||||
},
|
},
|
||||||
|
|
||||||
handleReadyStateChange: function(resolveFn, rejectFn, ev) {
|
handleReadyStateChange: function(resolveFn, rejectFn, ev) {
|
||||||
var xhr = this.xhr;
|
var xhr = this.xhr,
|
||||||
|
duration = Date.now() - this.start;
|
||||||
|
|
||||||
if (xhr.readyState !== 4)
|
if (xhr.readyState !== 4)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (xhr.status === 0 && xhr.statusText === '') {
|
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 {
|
else {
|
||||||
var response = new Response(
|
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) }))
|
Promise.all(Request.interceptors.map(function(fn) { return fn(response) }))
|
||||||
.then(resolveFn.bind(this, response))
|
.then(resolveFn.bind(this, response))
|
||||||
|
|
Loading…
Reference in a new issue