browser to server logging

Signed-off-by: Vladimir Mandic <mandic00@live.com>
This commit is contained in:
Vladimir Mandic
2024-11-23 10:47:06 -05:00
parent 6bd25a6f90
commit 8a1eaedc82
14 changed files with 120 additions and 86 deletions
+2 -39
View File
@@ -1,42 +1,5 @@
let lastState = {};
function request(url, data, handler, errorHandler) {
const xhr = new XMLHttpRequest();
xhr.open('POST', url, true);
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.timeout = 5000;
xhr.ontimeout = () => {
console.error('xhr.ontimeout', xhr);
errorHandler();
};
xhr.onerror = () => {
console.error('xhr.onerror', xhr);
errorHandler();
};
xhr.onabort = () => {
console.error('xhr.onabort', xhr);
errorHandler();
};
xhr.onreadystatechange = () => {
if (xhr.readyState === 4) {
if (xhr.status === 200) {
try {
const json = JSON.parse(xhr.responseText);
handler(json);
} catch (err) {
console.error('xhr.onreadystatechange', xhr, err);
errorHandler();
}
} else {
console.error('xhr.onreadystatechange', xhr);
errorHandler();
}
}
};
const req = JSON.stringify(data);
xhr.send(req);
}
function pad2(x) {
return x < 10 ? `0${x}` : x;
}
@@ -151,11 +114,11 @@ function requestProgress(id_task, progressEl, galleryEl, atEnd = null, onProgres
};
const onProgressErrorHandler = (err) => {
console.error('onProgressError', err);
error(`onProgressError: ${err}`);
done();
};
request('./internal/progress', { id_task, id_live_preview }, onProgressHandler, onProgressErrorHandler);
xhrPost('./internal/progress', { id_task, id_live_preview }, onProgressHandler, onProgressErrorHandler);
};
start(id_task, 0);
}