Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

O3-1258 Fatal errors cause crash loop #390

Merged
merged 2 commits into from
Apr 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/shell/esm-app-shell/src/index.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@
<h1>Application Error</h1>
<p>Something went wrong. Please try reloading.</p>
<p>If the problem persists contact your system administrator.</p>
<button class="bx--btn bx--btn--primary" onclick="location.reload()">Reload</button>
<div id="buttons">
<button class="bx--btn bx--btn--primary" onclick="location.reload()">Reload</button>
</div>
<div class="bx--snippet bx--snippet--single" >
<div tabindex="0" class="bx--snippet-container"
aria-label="Code Snippet Text">
Expand Down
26 changes: 18 additions & 8 deletions packages/shell/esm-app-shell/src/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,23 +117,17 @@ function connectivityChanged() {
function runShell() {
window.addEventListener("offline", connectivityChanged);
window.addEventListener("online", connectivityChanged);

return setupI18n()
.catch((err) => console.error(`Failed to initialize translations`, err))
.then(() => start());
}

function handleInitFailure(e: Error) {
console.error(e);

if (localStorage.getItem("openmrs:devtools")) {
clearDevOverrides();
}

renderApology(e.message);
renderFatalErrorPage(e.message);
}

function renderApology(message: string) {
function renderFatalErrorPage(message: string) {
const template = document.querySelector<HTMLTemplateElement>("#app-error");

if (template) {
Expand All @@ -145,6 +139,22 @@ function renderApology(message: string) {
message || "No additional information available.";
}

if (
localStorage.getItem("openmrs:devtools") &&
Object.keys(localStorage).some((k) =>
k.startsWith("import-map-override:")
)
) {
const appErrorActionButtons = fragment?.querySelector("#buttons");
if (appErrorActionButtons) {
const clearDevOverridesButton = document.createElement("button");
clearDevOverridesButton.className = "bx--btn";
clearDevOverridesButton.innerHTML = "Clear dev overrides";
clearDevOverridesButton.onclick = clearDevOverrides;
appErrorActionButtons.appendChild(clearDevOverridesButton);
}
}

document.body.appendChild(fragment);
}
}
Expand Down