@@ -668,7 +668,7 @@ actor BluetoothActor {
668668 log? . warn ( tags: [ . category( . connection) ] , " didDisconnect for unknown peripheral — dropped " )
669669 return
670670 }
671- let mappedError : PeripheralError ? = payload. error. flatMap { ( $0 as? CBError ) . map { PeripheralError . fromCBError ( $0 ) } }
671+ let mappedError : PeripheralError ? = payload. error. map { ( $0 as? CBError ) . map ( PeripheralError . fromCBError) ?? . unknown }
672672 let state : ConnectionState = . disconnected( reason: mappedError)
673673 connectionStates [ id] = state
674674 if let error = mappedError {
@@ -684,7 +684,7 @@ actor BluetoothActor {
684684 log? . warn ( tags: [ . category( . connection) ] , " didFailToConnect for unknown peripheral — dropped " )
685685 return
686686 }
687- let mappedError : PeripheralError ? = payload. error. flatMap { ( $0 as? CBError ) . map { PeripheralError . fromCBError ( $0 ) } }
687+ let mappedError : PeripheralError ? = payload. error. map { ( $0 as? CBError ) . map ( PeripheralError . fromCBError) ?? . unknown }
688688 let state : ConnectionState = . failed( reason: mappedError)
689689 connectionStates [ id] = state
690690 log? . warn ( tags: [ . peripheral( id) , . category( . connection) ] , " Peripheral connection failed with error: \( mappedError ?? . unknown) " )
@@ -780,14 +780,14 @@ final class BluetoothDelegateShim: NSObject, CBCentralManagerDelegate {
780780 let payload = ConnectionPayload ( peripheral: peripheral, error: nil )
781781 eventContinuation. yield ( . connected( payload) )
782782 }
783-
784- func centralManager( _ central: CBCentralManager , didDisconnectPeripheral peripheral: CBPeripheral , timestamp : CFAbsoluteTime , isReconnecting : Bool , error: Error ? ) {
783+
784+ func centralManager( _ central: CBCentralManager , didFailToConnect peripheral: CBPeripheral , error: Error ? ) {
785785 let payload = ConnectionPayload ( peripheral: peripheral, error: error)
786- eventContinuation. yield ( . disconnected ( payload) )
786+ eventContinuation. yield ( . connectFailed ( payload) )
787787 }
788788
789- func centralManager( _ central: CBCentralManager , didFailToConnect peripheral: CBPeripheral , error: Error ? ) {
789+ func centralManager( _ central: CBCentralManager , didDisconnectPeripheral peripheral: CBPeripheral , timestamp : CFAbsoluteTime , isReconnecting : Bool , error: Error ? ) {
790790 let payload = ConnectionPayload ( peripheral: peripheral, error: error)
791- eventContinuation. yield ( . connectFailed ( payload) )
791+ eventContinuation. yield ( . disconnected ( payload) )
792792 }
793793}
0 commit comments