Skip to content

Commit

Permalink
restart timeout on progress, catch error (#2170)
Browse files Browse the repository at this point in the history
* restart timeout on progress, catch error

* .

---------

Co-authored-by: CaCO3 <caco@ruinelli.ch>
  • Loading branch information
caco3 and CaCO3 authored Mar 12, 2023
1 parent ff81fcb commit 4dd41c4
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions sd-card/html/backup.html
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,13 @@ <h2>Restore Configuration</h2>
xhr.timeout = 5000; // time in milliseconds
}
else if (retry == 2) { // longer timeout
xhr.timeout = 20000; // time in milliseconds
xhr.timeout = 10000; // time in milliseconds
}
else if (retry == 3) { // longer timeout
xhr.timeout = 30000; // time in milliseconds
xhr.timeout = 20000; // time in milliseconds
}
else { // very long timeout
xhr.timeout = 60000; // time in milliseconds
xhr.timeout = 30000; // time in milliseconds
}

xhr.onload = () => { // Request finished
Expand All @@ -146,6 +146,20 @@ <h2>Restore Configuration</h2>
}
};

xhr.onprogress = (e) => { // XMLHttpRequest progress ... extend timeout
xhr.timeout = xhr.timeout + 500;
};

xhr.onerror = (e) => { // XMLHttpRequest error loading
console.log("Error on fetching " + url + "!");
if (retry > 5) {
setStatus("<span style=\"color: red\">Backup failed, please restart the device and try again!</span>");
}
else {
fetchFiles(urls, filesData, index, retry+1, zipFilename);
}
};

xhr.ontimeout = (e) => { // XMLHttpRequest timed out
console.log("Timeout on fetching " + url + "!");
if (retry > 5) {
Expand Down

0 comments on commit 4dd41c4

Please sign in to comment.