fix: await loadDoc, add empty render check, show stack trace
This commit is contained in:
@@ -70,13 +70,15 @@ async function loadDoc(name) {
|
|||||||
if (!resp.ok) throw new Error('HTTP ' + resp.status);
|
if (!resp.ok) throw new Error('HTTP ' + resp.status);
|
||||||
const md = await resp.text();
|
const md = await resp.text();
|
||||||
if (!wasm) throw new Error('WASM not initialized');
|
if (!wasm) throw new Error('WASM not initialized');
|
||||||
el.innerHTML = wasm.render(md);
|
var html = wasm.render(md);
|
||||||
document.querySelectorAll('.sidebar a.module-link').forEach(a => a.classList.remove('active'));
|
if (html.length === 0) throw new Error('WASM render returned empty HTML');
|
||||||
const link = document.querySelector('.sidebar a[data-module="' + name + '"]');
|
el.innerHTML = html;
|
||||||
|
document.querySelectorAll('.sidebar a.module-link').forEach(function(a) { a.classList.remove('active'); });
|
||||||
|
var link = document.querySelector('.sidebar a[data-module="' + name + '"]');
|
||||||
if (link) link.classList.add('active');
|
if (link) link.classList.add('active');
|
||||||
history.pushState(null, '', '#' + name);
|
history.pushState(null, '', '#' + name);
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
el.innerHTML = '<p style="color:red">Error: ' + e.message + '</p>';
|
el.innerHTML = '<p style="color:red">Error: ' + e.message + '</p><pre style="font-size:12px;background:#f8f8f8;padding:8px">' + e.stack + '</pre>';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -99,9 +101,9 @@ async function init() {
|
|||||||
window.location.reload();
|
window.location.reload();
|
||||||
};
|
};
|
||||||
var hash = location.hash.slice(1);
|
var hash = location.hash.slice(1);
|
||||||
loadDoc(hash || '01_auth');
|
await loadDoc(hash || '01_auth');
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
el.innerHTML = '<p style="color:red">Init error: ' + e.message + '</p>';
|
el.innerHTML = '<p style="color:red">Init error: ' + e.message + '</p><pre style="font-size:12px;background:#f8f8f8;padding:8px">' + e.stack + '</pre>';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user