diff options
author | Roopesh Chander <roop@roopc.net> | 2018-12-06 15:58:27 +0530 |
---|---|---|
committer | Roopesh Chander <roop@roopc.net> | 2018-12-07 12:36:19 +0530 |
commit | 8d26a3c5360a89605b2ecf6c5ad8edadd8eea590 (patch) | |
tree | 52f570268e04f8df77790dcfab40a560fa0d9df6 /WireGuard/WireGuard/UI/iOS/ErrorPresenter.swift | |
parent | Error presenter: Always handle the passed error (diff) | |
download | wireguard-apple-8d26a3c5360a89605b2ecf6c5ad8edadd8eea590.tar.xz wireguard-apple-8d26a3c5360a89605b2ecf6c5ad8edadd8eea590.zip |
Error handling: Cleanup Tunnels Manager errors
Signed-off-by: Roopesh Chander <roop@roopc.net>
Diffstat (limited to '')
-rw-r--r-- | WireGuard/WireGuard/UI/iOS/ErrorPresenter.swift | 49 |
1 files changed, 30 insertions, 19 deletions
diff --git a/WireGuard/WireGuard/UI/iOS/ErrorPresenter.swift b/WireGuard/WireGuard/UI/iOS/ErrorPresenter.swift index 2ae0cf0..35bbdec 100644 --- a/WireGuard/WireGuard/UI/iOS/ErrorPresenter.swift +++ b/WireGuard/WireGuard/UI/iOS/ErrorPresenter.swift @@ -6,27 +6,12 @@ import os.log class ErrorPresenter { static func errorMessage(for error: Error) -> (String, String) { - switch (error) { - // TunnelManagementError - case TunnelManagementError.tunnelAlreadyExistsWithThatName: - return ("Name already exists", "A tunnel with that name already exists") - case TunnelManagementError.tunnelInvalidName: - return ("Name already exists", "The tunnel name is invalid") - case TunnelManagementError.vpnSystemErrorOnAddTunnel: - return ("Unable to create tunnel", "Internal error") - case TunnelManagementError.vpnSystemErrorOnModifyTunnel: - return ("Unable to modify tunnel", "Internal error") - case TunnelManagementError.vpnSystemErrorOnRemoveTunnel: - return ("Unable to remove tunnel", "Internal error") + if let tunnelsManagerError = error as? TunnelsManagerError { + return errorMessage(forTunnelsManagerError: tunnelsManagerError) + } - // TunnelActivationError - case TunnelActivationError.tunnelActivationAttemptFailed: - return ("Activation failure", "The tunnel could not be activated due to an internal error") - case TunnelActivationError.tunnelActivationFailedInternalError: - return ("Activation failure", "The tunnel could not be activated due to an internal error") - case TunnelActivationError.tunnelActivationFailedNoInternetConnection: - return ("Activation failure", "No internet connection") + switch (error) { // Importing a zip file case ZipArchiveError.cantOpenInputZipFile: @@ -47,6 +32,32 @@ class ErrorPresenter { } } + private static func errorMessage(forTunnelsManagerError error: TunnelsManagerError) -> (String, String) { + switch (error) { + // Tunnels list management + case TunnelsManagerError.tunnelNameEmpty: + return ("No name provided", "Can't create tunnel with an empty name") + case TunnelsManagerError.tunnelAlreadyExistsWithThatName: + return ("Name already exists", "A tunnel with that name already exists") + case TunnelsManagerError.vpnSystemErrorOnListingTunnels: + return ("Unable to list tunnels", "Internal error") + case TunnelsManagerError.vpnSystemErrorOnAddTunnel: + return ("Unable to create tunnel", "Internal error") + case TunnelsManagerError.vpnSystemErrorOnModifyTunnel: + return ("Unable to modify tunnel", "Internal error") + case TunnelsManagerError.vpnSystemErrorOnRemoveTunnel: + return ("Unable to remove tunnel", "Internal error") + + // Tunnel activation + case TunnelsManagerError.tunnelActivationAttemptFailed: + return ("Activation failure", "The tunnel could not be activated due to an internal error") + case TunnelsManagerError.tunnelActivationFailedInternalError: + return ("Activation failure", "The tunnel could not be activated due to an internal error") + case TunnelsManagerError.tunnelActivationFailedNoInternetConnection: + return ("Activation failure", "No internet connection") + } + } + static func showErrorAlert(error: Error, from sourceVC: UIViewController?, onDismissal: (() -> Void)? = nil, onPresented: (() -> Void)? = nil) { guard let sourceVC = sourceVC else { return } |