diff --git a/Bitkit/Utilities/Errors.swift b/Bitkit/Utilities/Errors.swift index 410ea547..b1301a7b 100644 --- a/Bitkit/Utilities/Errors.swift +++ b/Bitkit/Utilities/Errors.swift @@ -1,7 +1,7 @@ import Foundation import LDKNode -enum CustomServiceError: Error { +enum CustomServiceError: LocalizedError { case nodeNotSetup case nodeNotStarted case onchainWalletNotInitialized @@ -12,14 +12,54 @@ enum CustomServiceError: Error { case regtestOnlyMethod case channelSizeExceedsMaximum case currencyRateUnavailable + + var errorDescription: String? { + switch self { + case .nodeNotSetup: + return "Node is not setup" + case .nodeNotStarted: + return "Node is not started" + case .onchainWalletNotInitialized: + return "Onchain wallet not created" + case .mnemonicNotFound: + return "Mnemonic not found" + case .nodeStillRunning: + return "Node is still running" + case .onchainWalletStillRunning: + return "Onchain wallet is still running" + case .invalidNodeSigningMessage: + return "Invalid node signing message" + case .regtestOnlyMethod: + return "Method only available in regtest environment" + case .channelSizeExceedsMaximum: + return "Channel size exceeds maximum allowed size" + case .currencyRateUnavailable: + return "Currency rate unavailable" + } + } } -enum KeychainError: Error { +enum KeychainError: LocalizedError { case failedToSave case failedToSaveAlreadyExists case failedToDelete case failedToLoad case keychainWipeNotAllowed + + var errorDescription: String? { + switch self { + case .failedToSave: + return "Failed to save to keychain" + case .failedToSaveAlreadyExists: + return "Failed to save to keychain: item already exists" + case .failedToDelete: + return "Failed to delete from keychain" + case .failedToLoad: + return "Failed to load from keychain" + case .keychainWipeNotAllowed: + return "Keychain wipe not allowed" + } + } } enum BlocktankError_deprecated: Error { diff --git a/Bitkit/ViewModels/AppViewModel.swift b/Bitkit/ViewModels/AppViewModel.swift index 3fbaf910..a71f618f 100644 --- a/Bitkit/ViewModels/AppViewModel.swift +++ b/Bitkit/ViewModels/AppViewModel.swift @@ -216,6 +216,9 @@ extension AppViewModel { } func toast(_ error: Error) { + if error is CancellationError { + return + } toast(type: .error, title: "Error", description: error.localizedDescription) }