Skip to content

Commit 33440e4

Browse files
authored
Merge pull request #24 from StarryInternet/better-centralmanager-errors
Don't wrap connection errors in its own case in CentralManagerError, to make it easier to query or case-match normal core bluetooth errors
2 parents 831b965 + 975146c commit 33440e4

2 files changed

Lines changed: 6 additions & 27 deletions

File tree

Sources/CombineCoreBluetooth/CentralManager/Interface+CentralManager.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ public struct CentralManager {
9090
.setFailureType(to: Error.self),
9191
didFailToConnectPeripheral
9292
.filter { p, _ in p == peripheral }
93-
.tryMap { p, error in
94-
throw CentralManagerError.failedToConnect(error as NSError?)
93+
.tryMap { _, error in
94+
throw error ?? CentralManagerError.unknownConnectionFailure
9595
}
9696
)
9797
.prefix(1)
Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,15 @@
11
import Foundation
22

33
public enum CentralManagerError: Error, Equatable {
4-
/// Thrown if there's a failure during connection to a peripheral
5-
case failedToConnect(NSError?)
4+
/// Thrown if there's a failure during connection to a peripheral, but there's no error information
5+
case unknownConnectionFailure
66
}
77

88
extension CentralManagerError: LocalizedError {
99
public var errorDescription: String? {
1010
switch self {
11-
case let .failedToConnect(error):
12-
return error?.localizedDescription
13-
}
14-
}
15-
16-
public var failureReason: String? {
17-
switch self {
18-
case let .failedToConnect(error):
19-
return error?.localizedFailureReason
20-
}
21-
}
22-
23-
public var recoverySuggestion: String? {
24-
switch self {
25-
case let .failedToConnect(error):
26-
return error?.localizedRecoverySuggestion
27-
}
28-
}
29-
30-
public var helpAnchor: String? {
31-
switch self {
32-
case let .failedToConnect(error):
33-
return error?.helpAnchor
11+
case .unknownConnectionFailure:
12+
return "Unknown failure connecting to the peripheral."
3413
}
3514
}
3615
}

0 commit comments

Comments
 (0)