Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/handle ble manager error cases #20

Merged

Conversation

SOGAPPS
Copy link
Contributor

@SOGAPPS SOGAPPS commented May 7, 2024

Update sendMessageCompletion to handle other BLEManagerError case with human-readable message

  • Return to original main barch code - using error
  • CHANGE: Make "OBDServiceError" enum public, so Client can use it to extract human-readable message

SOGAPPS added 3 commits May 7, 2024 11:33
…h human-readable message

- Current method retuns: "The operation couldn’t be completed. (SwiftOBD2.BLEManagerError error 2.)" for ".scanTimeout"
…h human-readable message

- Throw "bleError" instead of "error"
…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
@kkonteh97 kkonteh97 merged commit 032fcda into kkonteh97:main May 7, 2024
1 check passed
@SOGAPPS
Copy link
Contributor Author

SOGAPPS commented May 7, 2024

Let the UI Section (SwiftOBD2App) handle error message UI.
Reason: Reduce "SwiftOBD2" code complexity & over dependency

Here's an example of how you can use this in "SwiftOBD2App":

  1. Create a shared error handler class or struct:
class BLEErrorHandler {
    static func handle(error: Error) -> String {
        if let obdError = error as? OBDServiceError {
            // Handle specific cases of OBDServiceError
            switch obdError {
            case .noAdapterFound:
                return "No adapter found."
            case .notConnectedToVehicle:
                return "Not connected to the vehicle."
            case .adapterConnectionFailed(let underlyingError):
                return "Adapter connection failed with error: \(underlyingError)"
            case .scanFailed(let underlyingError):
                return "Scan failed with error: \(underlyingError)"
            case .clearFailed(let underlyingError):
                return "Clear failed with error: \(underlyingError)"
            case .commandFailed(let command, let error):
                return "Command '\(command)' failed with error: \(error)"
            }
        } else {
            // Handle other types of errors
            return "Error: \(error.localizedDescription)"
        }
    }
}

2. Use the handle function from ErrorHandler wherever you need to handle errors:
// Example usage in a view:
statusMessage = ErrorHandler.handle(error: error)

@kkonteh97
Copy link
Owner

I'll add that when I do some much needed refactoring.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants