Skip to content

Commit

Permalink
Update sendMessageCompletion to handle other BLEManagerError case wit…
Browse files Browse the repository at this point in the history
…h human-readable message

- Return to original main barch code - using error
- Make "OBDServiceError" enum public, so Client can use it to exract human-readable message
  • Loading branch information
SOGAPPS committed May 7, 2024
1 parent 542a2a9 commit c5b4158
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 19 deletions.
21 changes: 3 additions & 18 deletions Sources/SwiftOBD2/Communication/bleManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,7 @@ class BLEManager: NSObject, CommProtocol {
if let peripheral = peripheral {
continuation.resume(returning: peripheral)
} else if let error = error {
if let bleError = error as? BLEManagerError {
// Handle the BLEManagerError cases
continuation.resume(throwing: bleError)
} else {
continuation.resume(throwing: error)
}
continuation.resume(throwing: error)
}
self.foundPeripheralCompletion = nil
}
Expand Down Expand Up @@ -265,12 +260,7 @@ class BLEManager: NSObject, CommProtocol {
if let _ = peripheral {
continuation.resume()
} else if let error = error {
if let bleError = error as? BLEManagerError {
// Handle the BLEManagerError cases
continuation.resume(throwing: bleError)
} else {
continuation.resume(throwing: error)
}
continuation.resume(throwing: error)
}
}
connect(to: peripheral)
Expand Down Expand Up @@ -309,12 +299,7 @@ class BLEManager: NSObject, CommProtocol {
if let response = response {
continuation.resume(returning: response)
} else if let error = error {
if let bleError = error as? BLEManagerError {
// Handle the BLEManagerError cases
continuation.resume(throwing: bleError)
} else {
continuation.resume(throwing: error)
}
continuation.resume(throwing: error)
}
self.sendMessageCompletion = nil
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftOBD2/obd2service.swift
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ public struct MeasurementResult: Equatable {
public let unit: Unit
}

enum OBDServiceError: Error {
public enum OBDServiceError: Error {
case noAdapterFound
case notConnectedToVehicle
case adapterConnectionFailed(underlyingError: Error)
Expand Down

0 comments on commit c5b4158

Please sign in to comment.