소스 검색

Do not silently ignore errors not caused by user closing picker (#115)

Paulus Schoutsen 3 년 전
부모
커밋
ddbe525c99
1개의 변경된 파일5개의 추가작업 그리고 2개의 파일을 삭제
  1. 5 2
      src/connect.ts

+ 5 - 2
src/connect.ts

@@ -5,8 +5,11 @@ export const connect = async (button: InstallButton) => {
   let port: SerialPort | undefined;
   try {
     port = await navigator.serial.requestPort();
-  } catch (err) {
-    console.error("User cancelled request", err);
+  } catch (err: any) {
+    if ((err as DOMException).name === "NotFoundError") {
+      return;
+    }
+    alert(`Error: ${err.message}`);
     return;
   }