feat: improve error handling and logging in the web application
- Updated the error handling in `index.html` to include a retry button for failed app loads, enhancing user experience. - Added session storage management to prevent repeated reloads on errors. - Enhanced the `.gitignore` file to include log files, improving project cleanliness. - Included error logging in `main.js` to ensure better tracking of issues during app initialization.
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -14,3 +14,6 @@ htmlcov/
|
|||||||
.pytest_cache/
|
.pytest_cache/
|
||||||
*.cover
|
*.cover
|
||||||
*.plan.md
|
*.plan.md
|
||||||
|
|
||||||
|
# Logs
|
||||||
|
*.log
|
||||||
@@ -73,14 +73,30 @@
|
|||||||
var mainScript = document.getElementById("main-module");
|
var mainScript = document.getElementById("main-module");
|
||||||
if (mainScript) {
|
if (mainScript) {
|
||||||
mainScript.addEventListener("error", function() {
|
mainScript.addEventListener("error", function() {
|
||||||
|
var retryKey = "__dtLoadRetry";
|
||||||
|
try {
|
||||||
|
if (!sessionStorage.getItem(retryKey)) {
|
||||||
|
sessionStorage.setItem(retryKey, "1");
|
||||||
|
location.reload();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
sessionStorage.removeItem(retryKey);
|
||||||
|
} catch (_) {}
|
||||||
var loading = document.getElementById("loading");
|
var loading = document.getElementById("loading");
|
||||||
if (loading && !loading.classList.contains("hidden")) {
|
if (loading && !loading.classList.contains("hidden")) {
|
||||||
loading.classList.add("hidden");
|
loading.classList.add("hidden");
|
||||||
var err = document.getElementById("error");
|
}
|
||||||
if (err) {
|
var err = document.getElementById("error");
|
||||||
err.hidden = false;
|
if (err) {
|
||||||
err.textContent = "Failed to load app. Check connection and try again.";
|
err.hidden = false;
|
||||||
}
|
err.textContent = "";
|
||||||
|
err.appendChild(document.createTextNode("Failed to load app. Check connection and try again. "));
|
||||||
|
var retryBtn = document.createElement("button");
|
||||||
|
retryBtn.type = "button";
|
||||||
|
retryBtn.className = "error-retry";
|
||||||
|
retryBtn.textContent = "Retry";
|
||||||
|
retryBtn.addEventListener("click", function() { location.reload(); });
|
||||||
|
err.appendChild(retryBtn);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -68,6 +68,9 @@ applyLangToUi();
|
|||||||
|
|
||||||
logger.info("App init", "lang=" + state.lang);
|
logger.info("App init", "lang=" + state.lang);
|
||||||
|
|
||||||
|
try {
|
||||||
|
sessionStorage.removeItem("__dtLoadRetry");
|
||||||
|
} catch (_) {}
|
||||||
window.__dtReady = true;
|
window.__dtReady = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user