今いくつかのエラーパターンがあるシステムを作っています。
そしてエラーがある時はalert(e)
でその内容を表示しています。
そのエラーの中から特定の、具体的にはInvalidStateError
の時だけメッセージを「読み取りを中止します」にしたいです。
以下ソースです。do内のfinishButton
クリック時に該当エラーが出ます
よろしくお願いします。
startButton.addEventListener('click', async () => { let device; try { device = await window.navigator.usb.requestDevice({ filters: [{ vendorId: 0x054c, productId: 0x06C3, }]}); console.log("open"); await device.open(); } catch (e) { console.log(e); alert(e); throw e; } try { console.log("selectConfiguration"); await device.selectConfiguration(1); console.log("claimInterface"); await device.claimInterface(0); console.log(device); startButton.style.display = 'none'; readingMessage.style.display = 'none'; waitingMessage.style.display = 'block'; finishButton.style.display = 'block'; do { await session(device); await sleep(100); finishButton.addEventListener('click',function() { device.close(); }); } while (true); } catch (e) { console.log(e); alert(e); try { device.close(); } catch (e) { console.log(e); } throw e; } });
回答1件
あなたの回答
tips
プレビュー