Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
this.exchangeAtomicImpl(async () => {
try {
const msgIn = apdu.toString("hex");
log("apdu", `=> ${msgIn}`);
const data = await merge(
this.notifyObservable.pipe(receiveAPDU),
sendAPDU(this.write, apdu, this.mtuSize)
).toPromise();
const msgOut = data.toString("hex");
log("apdu", `<= ${msgOut}`);
return data;
} catch (e) {
log("ble-error", "exchange got " + String(e));
if (this.notYetDisconnected) {
// in such case we will always disconnect because something is bad.
this.device.gatt.disconnect();
}
throw e;
}
});
this.exchangeAtomicImpl(async () => {
try {
const msgIn = apdu.toString("hex");
log("apdu", `=> ${msgIn}`);
const data = await merge(
this.notifyObservable.pipe(receiveAPDU),
sendAPDU(this.write, apdu, this.mtuSize)
).toPromise();
const msgOut = data.toString("hex");
log("apdu", `<= ${msgOut}`);
return data;
} catch (e) {
log("ble-error", "exchange got " + String(e));
if (this.notYetDisconnected) {
// in such case we will always disconnect because something is bad.
await bleManager.cancelDeviceConnection(this.id).catch(() => {}); // but we ignore if disconnect worked.
}
throw remapError(e);
}
});
this.exchangeAtomicImpl(async () => {
try {
const msgIn = apdu.toString("hex");
log("apdu", `=> ${msgIn}`);
const data = await merge(
this.notifyObservable.pipe(receiveAPDU),
sendAPDU(this.write, apdu, this.mtuSize)
).toPromise();
const msgOut = data.toString("hex");
log("apdu", `<= ${msgOut}`);
return data;
} catch (e) {
log("ble-error", "exchange got " + String(e));
if (this.notYetDisconnected) {
// in such case we will always disconnect because something is bad.
await disconnectDevice(this.device).catch(() => {}); // but we ignore if disconnect worked.
}
throw e;
}
});