From db43cb3e99504d9c2ffa82410af03c2090371cce Mon Sep 17 00:00:00 2001 From: David Lechner Date: Wed, 12 Oct 2022 18:24:58 -0500 Subject: [PATCH] remove use of deprecated DomException code property --- src/ble/sagas.ts | 25 +++++-------------------- src/firmware/sagas.ts | 10 ++-------- src/lwp3-bootloader/sagas-ble.ts | 4 ++-- 3 files changed, 9 insertions(+), 30 deletions(-) diff --git a/src/ble/sagas.ts b/src/ble/sagas.ts index f291af2a..dd532d64 100644 --- a/src/ble/sagas.ts +++ b/src/ble/sagas.ts @@ -133,10 +133,7 @@ function* handleBleConnectPybricks(): Generator { ], }) .catch((err) => { - if ( - err instanceof DOMException && - err.code === DOMException.NOT_FOUND_ERR - ) { + if (err instanceof DOMException && err.name === 'NotFoundError') { // this means the user clicked the cancel button in the scan dialog return undefined; } @@ -192,10 +189,7 @@ function* handleBleConnectPybricks(): Generator { const deviceInfoService = yield* call(() => server.getPrimaryService(deviceInformationServiceUUID).catch((err) => { - if ( - err instanceof DOMException && - err.code === DOMException.NOT_FOUND_ERR - ) { + if (err instanceof DOMException && err.name === 'NotFoundError') { return undefined; } @@ -263,10 +257,7 @@ function* handleBleConnectPybricks(): Generator { const pnpIdChar = yield* call(() => deviceInfoService.getCharacteristic(pnpIdUUID).catch((err) => { - if ( - err instanceof DOMException && - err.code === DOMException.NOT_FOUND_ERR - ) { + if (err instanceof DOMException && err.name === 'NotFoundError') { // istanbul ignore if if (process.env.NODE_ENV !== 'test') { console.warn( @@ -288,10 +279,7 @@ function* handleBleConnectPybricks(): Generator { const pybricksService = yield* call(() => server.getPrimaryService(pybricksServiceUUID).catch((err) => { - if ( - err instanceof DOMException && - err.code === DOMException.NOT_FOUND_ERR - ) { + if (err instanceof DOMException && err.name === 'NotFoundError') { return undefined; } @@ -353,10 +341,7 @@ function* handleBleConnectPybricks(): Generator { const uartService = yield* call(() => server.getPrimaryService(nordicUartServiceUUID).catch((err) => { - if ( - err instanceof DOMException && - err.code === DOMException.NOT_FOUND_ERR - ) { + if (err instanceof DOMException && err.name === 'NotFoundError') { return undefined; } diff --git a/src/firmware/sagas.ts b/src/firmware/sagas.ts index 3045716b..761fcd8c 100644 --- a/src/firmware/sagas.ts +++ b/src/firmware/sagas.ts @@ -638,10 +638,7 @@ function* handleFlashUsbDfu(action: ReturnType): Gen ], }) .catch((err) => { - if ( - err instanceof DOMException && - err.code === DOMException.NOT_FOUND_ERR - ) { + if (err instanceof DOMException && err.name === 'NotFoundError') { // user clicked cancel button return undefined; } @@ -685,10 +682,7 @@ function* handleFlashUsbDfu(action: ReturnType): Gen defer.push(() => dfu.close().catch((err) => { - if ( - err instanceof DOMException && - err.code === DOMException.NETWORK_ERR - ) { + if (err instanceof DOMException && err.name === 'NetworkError') { // device was disconnected return; } diff --git a/src/lwp3-bootloader/sagas-ble.ts b/src/lwp3-bootloader/sagas-ble.ts index 6760ebe5..ceb06492 100644 --- a/src/lwp3-bootloader/sagas-ble.ts +++ b/src/lwp3-bootloader/sagas-ble.ts @@ -75,7 +75,7 @@ function* handleConnect(): Generator { }), ); } catch (err) { - if (err instanceof DOMException && err.code === DOMException.NOT_FOUND_ERR) { + if (err instanceof DOMException && err.name === 'NotFoundError') { // this can happen if the use cancels the dialog yield* put(didFailToConnect(Reason.Canceled)); } else { @@ -119,7 +119,7 @@ function* handleConnect(): Generator { } catch (err) { server.disconnect(); yield* takeMaybe(disconnectChannel); - if (err instanceof DOMException && err.code === DOMException.NOT_FOUND_ERR) { + if (err instanceof DOMException && err.name === 'NotFoundError') { yield* put(didFailToConnect(Reason.GattServiceNotFound)); } else { yield* put(didFailToConnect(Reason.Unknown, ensureError(err)));