Frontend: Improve status polling in server.js

Signed-off-by: Michael Mayer <michael@photoprism.app>
This commit is contained in:
Michael Mayer 2023-03-27 21:47:10 +02:00
parent 8bfd95ddc4
commit b4ecadda9d

View file

@ -36,8 +36,17 @@ function poll(interval, maxAttempts) {
try {
const xhr = new XMLHttpRequest();
xhr.open("GET", config.apiUri + "/status", false);
xhr.onload = function () {
if (this.status === 200) {
return resolve();
} else {
throw new Error("request failed");
}
};
xhr.onerror = function () {
throw new Error("request failed");
};
xhr.send();
return resolve();
} catch {
if (maxAttempts && attempts === maxAttempts) {
return reject(new Error("exceeded max attempts"));