From 12db4a97c6b6c1ab623bfcba4e7892c50f05fa46 Mon Sep 17 00:00:00 2001 From: Claas Date: Fri, 15 Sep 2023 13:43:50 +0200 Subject: [PATCH] Improve error handling --- src/lib/SerialPorts.svelte | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/lib/SerialPorts.svelte b/src/lib/SerialPorts.svelte index 58d36b4..fa317de 100644 --- a/src/lib/SerialPorts.svelte +++ b/src/lib/SerialPorts.svelte @@ -32,11 +32,17 @@ // Known working usb devices const portFilter = [{ usbVendorId: 6790, usbProductId: 29987 }]; - function connect() { - navigator.serial.requestPort({ filters: portFilter }).then((port) => { - availablePorts.set(port, port.getInfo()); - quickUpdateHack(); - }); + async function connect() { + let port; + try { + port = await navigator.serial.requestPort({ filters: portFilter }); + } catch (error) { + console.warn("User cancelled port selection", error); + return; + } + + availablePorts.set(port, port.getInfo()); + quickUpdateHack(); } function quickUpdateHack() {