From c9267ba634f5699318502035c03fa281361cc581 Mon Sep 17 00:00:00 2001 From: Roopesh Chander Date: Thu, 6 Dec 2018 16:13:48 +0530 Subject: Error handling: Introduce a WireGuardAppError protocol to manage errors The alert strings shall be located next to where the errors are declared. Signed-off-by: Roopesh Chander --- WireGuard/WireGuard/VPN/TunnelsManager.swift | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) (limited to 'WireGuard/WireGuard/VPN/TunnelsManager.swift') diff --git a/WireGuard/WireGuard/VPN/TunnelsManager.swift b/WireGuard/WireGuard/VPN/TunnelsManager.swift index 77eb8e5..03d1a45 100644 --- a/WireGuard/WireGuard/VPN/TunnelsManager.swift +++ b/WireGuard/WireGuard/VPN/TunnelsManager.swift @@ -16,7 +16,8 @@ protocol TunnelsManagerActivationDelegate: class { func tunnelActivationFailed(tunnel: TunnelContainer, error: TunnelsManagerError) } -enum TunnelsManagerError: Error { +enum TunnelsManagerError: WireGuardAppError { + // Tunnels list management case tunnelNameEmpty case tunnelAlreadyExistsWithThatName case vpnSystemErrorOnListingTunnels @@ -24,9 +25,34 @@ enum TunnelsManagerError: Error { case vpnSystemErrorOnModifyTunnel case vpnSystemErrorOnRemoveTunnel + // Tunnel activation case tunnelActivationAttemptFailed // startTunnel() throwed case tunnelActivationFailedInternalError // startTunnel() succeeded, but activation failed case tunnelActivationFailedNoInternetConnection // startTunnel() succeeded, but activation failed since no internet + + func alertText() -> (String, String) { + switch (self) { + case .tunnelNameEmpty: + return ("No name provided", "Can't create tunnel with an empty name") + case .tunnelAlreadyExistsWithThatName: + return ("Name already exists", "A tunnel with that name already exists") + case .vpnSystemErrorOnListingTunnels: + return ("Unable to list tunnels", "Internal error") + case .vpnSystemErrorOnAddTunnel: + return ("Unable to create tunnel", "Internal error") + case .vpnSystemErrorOnModifyTunnel: + return ("Unable to modify tunnel", "Internal error") + case .vpnSystemErrorOnRemoveTunnel: + return ("Unable to remove tunnel", "Internal error") + + case .tunnelActivationAttemptFailed: + return ("Activation failure", "The tunnel could not be activated due to an internal error") + case .tunnelActivationFailedInternalError: + return ("Activation failure", "The tunnel could not be activated due to an internal error") + case .tunnelActivationFailedNoInternetConnection: + return ("Activation failure", "No internet connection") + } + } } enum TunnelsManagerResult { -- cgit v1.2.3-59-g8ed1b