aboutsummaryrefslogtreecommitdiffstats
path: root/WireGuard/WireGuard/UI
diff options
context:
space:
mode:
authorRoopesh Chander <roop@roopc.net>2018-11-01 16:58:33 +0530
committerRoopesh Chander <roop@roopc.net>2018-11-01 16:58:33 +0530
commit3611f8cf5afe709a9d84a4edd68666480ed04223 (patch)
tree398fe7bb74c37976d8deab322e88ba3f6442e6c9 /WireGuard/WireGuard/UI
parentTunnelsManager: Better errors (diff)
downloadwireguard-apple-3611f8cf5afe709a9d84a4edd68666480ed04223.tar.xz
wireguard-apple-3611f8cf5afe709a9d84a4edd68666480ed04223.zip
Tunnel errors: Consolidate tunnel activation errors into ErrorPresenter
Signed-off-by: Roopesh Chander <roop@roopc.net>
Diffstat (limited to 'WireGuard/WireGuard/UI')
-rw-r--r--WireGuard/WireGuard/UI/iOS/ErrorPresenter.swift28
-rw-r--r--WireGuard/WireGuard/UI/iOS/TunnelDetailTableViewController.swift12
-rw-r--r--WireGuard/WireGuard/UI/iOS/TunnelsListTableViewController.swift12
3 files changed, 36 insertions, 16 deletions
diff --git a/WireGuard/WireGuard/UI/iOS/ErrorPresenter.swift b/WireGuard/WireGuard/UI/iOS/ErrorPresenter.swift
index 8cdb921..e7733b3 100644
--- a/WireGuard/WireGuard/UI/iOS/ErrorPresenter.swift
+++ b/WireGuard/WireGuard/UI/iOS/ErrorPresenter.swift
@@ -7,6 +7,8 @@ import os.log
class ErrorPresenter {
static func errorMessage(for error: Error) -> (String, String)? {
switch (error) {
+
+ // TunnelManagementError
case TunnelManagementError.tunnelAlreadyExistsWithThatName:
return ("Name already in use", "A tunnel with that name already exists. Please pick a different name.")
case TunnelManagementError.vpnSystemErrorOnAddTunnel:
@@ -15,6 +17,32 @@ class ErrorPresenter {
return ("Could not modify tunnel", "Internal error")
case TunnelManagementError.vpnSystemErrorOnRemoveTunnel:
return ("Could not remove tunnel", "Internal error")
+
+ // TunnelActivationError
+ case TunnelActivationError.noEndpoint:
+ return ("Endpoint missing", "There must be at least one peer with an endpoint")
+ case TunnelActivationError.dnsResolutionFailed:
+ return ("DNS Failure", "One or more endpoint domains could not be resolved")
+ case TunnelActivationError.tunnelActivationFailed:
+ return ("Activation failed", "The tunnel could not be activated because of an internal error")
+ case TunnelActivationError.attemptingActivationWhenAnotherTunnelIsBusy(let otherTunnelStatus):
+ let statusString: String = {
+ switch (otherTunnelStatus) {
+ case .active: fallthrough
+ case .reasserting: fallthrough
+ case .restarting:
+ return "active"
+ case .activating: fallthrough
+ case .resolvingEndpointDomains:
+ return "being activated"
+ case .deactivating:
+ return "being deactivated"
+ case .inactive:
+ fatalError()
+ }
+ }()
+ return ("Activation failed", "Another tunnel is currently \(statusString). Only one tunnel can be in operation at a time.")
+
default:
os_log("ErrorPresenter: Error not presented: %{public}@", log: OSLog.default, type: .error, "\(error)")
return nil
diff --git a/WireGuard/WireGuard/UI/iOS/TunnelDetailTableViewController.swift b/WireGuard/WireGuard/UI/iOS/TunnelDetailTableViewController.swift
index 14d715a..dc63258 100644
--- a/WireGuard/WireGuard/UI/iOS/TunnelDetailTableViewController.swift
+++ b/WireGuard/WireGuard/UI/iOS/TunnelDetailTableViewController.swift
@@ -149,15 +149,11 @@ extension TunnelDetailTableViewController {
cell.onSwitchToggled = { [weak self] isOn in
guard let s = self else { return }
if (isOn) {
- s.tunnelsManager.startActivation(of: s.tunnel) { [weak self] error in
+ s.tunnelsManager.startActivation(of: s.tunnel) { [weak s] error in
if let error = error {
- switch (error) {
- case TunnelActivationError.noEndpoint:
- self?.showErrorAlert(title: "Endpoint missing", message: "There must be at least one peer with an endpoint")
- case TunnelActivationError.dnsResolutionFailed:
- self?.showErrorAlert(title: "DNS Failure", message: "One or more endpoint domains could not be resolved")
- default:
- self?.showErrorAlert(title: "Internal error", message: "The tunnel could not be activated")
+ ErrorPresenter.showErrorAlert(error: error, from: s)
+ DispatchQueue.main.async {
+ cell.statusSwitch.isOn = false
}
}
}
diff --git a/WireGuard/WireGuard/UI/iOS/TunnelsListTableViewController.swift b/WireGuard/WireGuard/UI/iOS/TunnelsListTableViewController.swift
index 3ef672a..66b404c 100644
--- a/WireGuard/WireGuard/UI/iOS/TunnelsListTableViewController.swift
+++ b/WireGuard/WireGuard/UI/iOS/TunnelsListTableViewController.swift
@@ -245,15 +245,11 @@ extension TunnelsListTableViewController {
cell.onSwitchToggled = { [weak self] isOn in
guard let s = self, let tunnelsManager = s.tunnelsManager else { return }
if (isOn) {
- tunnelsManager.startActivation(of: tunnel) { error in
+ tunnelsManager.startActivation(of: tunnel) { [weak s] error in
if let error = error {
- switch (error) {
- case TunnelActivationError.noEndpoint:
- self?.showErrorAlert(title: "Endpoint missing", message: "There must be at least one peer with an endpoint")
- case TunnelActivationError.dnsResolutionFailed:
- self?.showErrorAlert(title: "DNS Failure", message: "One or more endpoint domains could not be resolved")
- default:
- self?.showErrorAlert(title: "Internal error", message: "The tunnel could not be activated")
+ ErrorPresenter.showErrorAlert(error: error, from: s)
+ DispatchQueue.main.async {
+ cell.statusSwitch.isOn = false
}
}
}