How to use the @ledgerhq/errors.CantOpenDevice function in @ledgerhq/errors

To help you get started, we’ve selected a few @ledgerhq/errors examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github LedgerHQ / ledgerjs / packages / hw-transport-node-hid-singleton / src / TransportNodeHid.js View on Github external
return Promise.resolve().then(() => {
      if (transportInstance) {
        log("hid-verbose", "reusing opened transport instance");
        return transportInstance;
      }

      const device = getDevices()[0];
      if (!device) throw new CantOpenDevice("no device found");
      log("hid-verbose", "new HID transport");
      transportInstance = new TransportNodeHidSingleton(
        new HID.HID(device.path)
      );
      const unlisten = listenDevices(
        () => {},
        () => {
          // assume any ledger disconnection concerns current transport
          if (transportInstance) {
            transportInstance.emit("disconnect");
          }
        }
      );
      const onDisconnect = () => {
        if (!transportInstance) return;
        log("hid-verbose", "transport instance was disconnected");
github LedgerHQ / ledgerjs / packages / react-native-hw-transport-ble / src / BleTransport.js View on Github external
log("ble-verbose", `connectToDevice(${deviceOrId})`);
      try {
        device = await bleManager.connectToDevice(deviceOrId, connectOptions);
      } catch (e) {
        if (e.errorCode === BleErrorCode.DeviceMTUChangeFailed) {
          // eslint-disable-next-line require-atomic-updates
          connectOptions = {};
          device = await bleManager.connectToDevice(deviceOrId);
        } else {
          throw e;
        }
      }
    }

    if (!device) {
      throw new CantOpenDevice();
    }
  } else {
    device = deviceOrId;
  }

  if (!(await device.isConnected())) {
    log("ble-verbose", "not connected. connecting...");
    try {
      await device.connect(connectOptions);
    } catch (e) {
      if (e.errorCode === BleErrorCode.DeviceMTUChangeFailed) {
        // eslint-disable-next-line require-atomic-updates
        connectOptions = {};
        await device.connect();
      } else {
        throw e;
github LedgerHQ / ledgerjs / packages / hw-transport-node-ble / src / TransportNodeBle.js View on Github external
async function open(deviceOrId: Device | string, needsReconnect: boolean) {
  let device;
  if (typeof deviceOrId === "string") {
    if (transportsCache[deviceOrId]) {
      log("ble-verbose", "Transport in cache, using that.");
      return transportsCache[deviceOrId];
    }
  } else {
    device = deviceOrId;
  }

  if (!device) {
    throw new CantOpenDevice();
  }

  await availability.pipe(first(enabled => enabled)).toPromise();

  if (isDeviceDisconnected(device)) {
    log("ble-verbose", "not connected. connecting...");
    await connectDevice(device);
  }

  const {
    notifyC,
    writeC,
    deviceModel
  } = await retrieveServiceAndCharacteristics(device);

  const [observable, monitoringReady] = monitorCharacteristic(notifyC);
github LedgerHQ / ledger-live-common / src / hw / deviceAccess.js View on Github external
.catch(e => {
        finish();
        if (e instanceof BluetoothRequired) throw e;
        if (e instanceof TransportWebUSBGestureRequired) throw e;
        if (e instanceof TransportInterfaceNotAvailable) throw e;
        throw new CantOpenDevice(e.message);
      })
      .then(transport => {