From 70b9050cb77445ff2ec89cc26f6cf33c7d208e2c Mon Sep 17 00:00:00 2001 From: Nikolay Tatarinov Date: Tue, 3 Mar 2026 00:10:30 +0300 Subject: [PATCH] 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. --- .gitignore | 3 +++ webapp/index.html | 26 +++++++++++++++++++++----- webapp/js/main.js | 3 +++ 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 268f9f4..2970a06 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,6 @@ htmlcov/ .pytest_cache/ *.cover *.plan.md + +# Logs +*.log \ No newline at end of file diff --git a/webapp/index.html b/webapp/index.html index 5e7d1c6..deb67e2 100644 --- a/webapp/index.html +++ b/webapp/index.html @@ -73,14 +73,30 @@ var mainScript = document.getElementById("main-module"); if (mainScript) { 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"); if (loading && !loading.classList.contains("hidden")) { loading.classList.add("hidden"); - var err = document.getElementById("error"); - if (err) { - err.hidden = false; - err.textContent = "Failed to load app. Check connection and try again."; - } + } + var err = document.getElementById("error"); + if (err) { + 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); } }); } diff --git a/webapp/js/main.js b/webapp/js/main.js index 099bf06..f942ea6 100644 --- a/webapp/js/main.js +++ b/webapp/js/main.js @@ -68,6 +68,9 @@ applyLangToUi(); logger.info("App init", "lang=" + state.lang); +try { + sessionStorage.removeItem("__dtLoadRetry"); +} catch (_) {} window.__dtReady = true; /**