Skip to content

Commit

Permalink
feat: error alert
Browse files Browse the repository at this point in the history
  • Loading branch information
Xiphoseer committed Jan 10, 2025
1 parent aa48ecd commit 3828f29
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions crates/sdo-web/index.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import init, { Handle } from './pkg/sdo_web.js';

function onError(e) {
console.error(e);
alert(e instanceof Error ? `ERROR ${e.name}: ${e.message}` : e);
}

async function run() {
await init();

Expand All @@ -13,7 +18,7 @@ async function run() {
const exportToPdfBtn = document.getElementById('export-to-pdf');

const h = new Handle(outputEl, inputField);
await h.init();
await h.init().catch(onError);

/*async function uploadFile(file) {
const buf = await file.arrayBuffer();
Expand Down Expand Up @@ -196,12 +201,13 @@ async function run() {
async function onHashChange(hash) {
handle(hash)
}
// Init
handle(decodeURIComponent(window.location.hash));

addEventListener('hashchange', (event) => {
onHashChange(decodeURIComponent(new URL(event.newURL).hash))
})

// Init
await handle(decodeURIComponent(window.location.hash)).catch(onError);
}

run();

0 comments on commit 3828f29

Please sign in to comment.