Skip to content

Commit

Permalink
Merge pull request #65 from inthepocket/feature/reject-promise-instea…
Browse files Browse the repository at this point in the history
…d-of-native-exception

Replace throwing of IllegalStateException with onError
  • Loading branch information
mikolak authored Nov 16, 2020
2 parents d535f70 + a3bf4af commit cb3194c
Showing 1 changed file with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,8 @@ public void getKnownDevices(String[] deviceIdentifiers,
OnSuccessCallback<Device[]> onSuccessCallback,
OnErrorCallback onErrorCallback) {
if (rxBleClient == null) {
throw new IllegalStateException("BleManager not created when tried to get known devices");
onErrorCallback.onError(new BleError(BleErrorCode.BluetoothManagerDestroyed, "BleManager not created when tried to get known devices", null));
return;
}

List<Device> knownDevices = new ArrayList<>();
Expand All @@ -384,7 +385,8 @@ public void getConnectedDevices(String[] serviceUUIDs,
OnSuccessCallback<Device[]> onSuccessCallback,
OnErrorCallback onErrorCallback) {
if (rxBleClient == null) {
throw new IllegalStateException("BleManager not created when tried to get connected devices");
onErrorCallback.onError(new BleError(BleErrorCode.BluetoothManagerDestroyed, "BleManager not created when tried to get connected devices", null));
return;
}

if (serviceUUIDs.length == 0) {
Expand Down Expand Up @@ -425,7 +427,8 @@ public void connectToDevice(String deviceIdentifier,
OnEventCallback<ConnectionState> onConnectionStateChangedCallback,
OnErrorCallback onErrorCallback) {
if (rxBleClient == null) {
throw new IllegalStateException("BleManager not created when tried to connect to device");
onErrorCallback.onError(new BleError(BleErrorCode.BluetoothManagerDestroyed, "BleManager not created when tried to connect to device", null));
return;
}

final RxBleDevice device = rxBleClient.getBleDevice(deviceIdentifier);
Expand All @@ -449,7 +452,8 @@ public void cancelDeviceConnection(String deviceIdentifier,
OnSuccessCallback<Device> onSuccessCallback,
OnErrorCallback onErrorCallback) {
if (rxBleClient == null) {
throw new IllegalStateException("BleManager not created when tried to cancel device connection");
onErrorCallback.onError(new BleError(BleErrorCode.BluetoothManagerDestroyed, "BleManager not created when tried to cancel device connection", null));
return;
}

final RxBleDevice device = rxBleClient.getBleDevice(deviceIdentifier);
Expand All @@ -470,7 +474,8 @@ public void isDeviceConnected(String deviceIdentifier,
OnSuccessCallback<Boolean> onSuccessCallback,
OnErrorCallback onErrorCallback) {
if (rxBleClient == null) {
throw new IllegalStateException("BleManager not created when tried to check if device is connected");
onErrorCallback.onError(new BleError(BleErrorCode.BluetoothManagerDestroyed, "BleManager not created when tried to check if device is connected", null));
return;
}

final RxBleDevice device = rxBleClient.getBleDevice(deviceIdentifier);
Expand Down Expand Up @@ -1218,7 +1223,8 @@ private void safeStartDeviceScan(final UUID[] uuids,
final OnEventCallback<ScanResult> onEventCallback,
final OnErrorCallback onErrorCallback) {
if (rxBleClient == null) {
throw new IllegalStateException("BleManager not created when tried to start device scan");
onErrorCallback.onError(new BleError(BleErrorCode.BluetoothManagerDestroyed, "BleManager not created when tried to start device scan", null));
return;
}

ScanSettings scanSettings = new ScanSettings.Builder()
Expand Down

0 comments on commit cb3194c

Please sign in to comment.