From 495b0174498ba458537f62b1b81bfbbd54827603 Mon Sep 17 00:00:00 2001 From: Roopesh Chander Date: Tue, 30 Oct 2018 00:24:50 +0530 Subject: [PATCH] VPN: Better error messages --- .../UI/iOS/TunnelDetailTableViewController.swift | 14 +++++++++++--- .../UI/iOS/TunnelsListTableViewController.swift | 11 ++++++++++- WireGuard/WireGuard/VPN/TunnelsManager.swift | 7 ++++++- 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/WireGuard/WireGuard/UI/iOS/TunnelDetailTableViewController.swift b/WireGuard/WireGuard/UI/iOS/TunnelDetailTableViewController.swift index d5b75b3..d86c1d6 100644 --- a/WireGuard/WireGuard/UI/iOS/TunnelDetailTableViewController.swift +++ b/WireGuard/WireGuard/UI/iOS/TunnelDetailTableViewController.swift @@ -165,11 +165,19 @@ extension TunnelDetailTableViewController { let cell = tableView.dequeueReusableCell(withIdentifier: TunnelDetailTableViewStatusCell.id, for: indexPath) as! TunnelDetailTableViewStatusCell cell.tunnel = self.tunnel cell.onSwitchToggled = { [weak self] isOn in - cell.isSwitchInteractionEnabled = false guard let s = self else { return } if (isOn) { - s.tunnelsManager.startActivation(of: s.tunnel) { error in - print("Error while activating: \(String(describing: error))") + s.tunnelsManager.startActivation(of: s.tunnel) { [weak self] error in + if let error = error { + switch (error) { + case TunnelsManagerError.noEndpoint: + self?.showErrorAlert(title: "Endpoint missing", message: "There must be atleast one peer with an endpoint") + case TunnelsManagerError.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") + } + } } } else { s.tunnelsManager.startDeactivation(of: s.tunnel) { error in diff --git a/WireGuard/WireGuard/UI/iOS/TunnelsListTableViewController.swift b/WireGuard/WireGuard/UI/iOS/TunnelsListTableViewController.swift index fa8e3ce..f008785 100644 --- a/WireGuard/WireGuard/UI/iOS/TunnelsListTableViewController.swift +++ b/WireGuard/WireGuard/UI/iOS/TunnelsListTableViewController.swift @@ -232,7 +232,16 @@ extension TunnelsListTableViewController { guard let s = self, let tunnelsManager = s.tunnelsManager else { return } if (isOn) { tunnelsManager.startActivation(of: tunnel) { error in - print("Error while activating: \(String(describing: error))") + if let error = error { + switch (error) { + case TunnelsManagerError.noEndpoint: + self?.showErrorAlert(title: "Endpoint missing", message: "There must be atleast one peer with an endpoint") + case TunnelsManagerError.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") + } + } } } else { tunnelsManager.startDeactivation(of: tunnel) { error in diff --git a/WireGuard/WireGuard/VPN/TunnelsManager.swift b/WireGuard/WireGuard/VPN/TunnelsManager.swift index 6559382..749b83d 100644 --- a/WireGuard/WireGuard/VPN/TunnelsManager.swift +++ b/WireGuard/WireGuard/VPN/TunnelsManager.swift @@ -265,6 +265,7 @@ class TunnelContainer: NSObject { if let endpoints = dnsResolver.resolveWithoutNetworkRequests() { guard (endpoints.contains(where: { $0 != nil })) else { completionHandler(TunnelsManagerError.noEndpoint) + status = .inactive return } self.tunnelProvider.loadFromPreferences { [weak self] (error) in @@ -278,7 +279,10 @@ class TunnelContainer: NSObject { } catch (let error) { os_log("Failed to activate tunnel: %{public}@", log: OSLog.default, type: .debug, "\(error)") completionHandler(error) + s.status = .inactive + return } + completionHandler(nil) } } else { self.dnsResolver = dnsResolver @@ -302,7 +306,8 @@ class TunnelContainer: NSObject { try session.startTunnel(options: tunnelOptions) } catch (let error) { os_log("Failed to activate tunnel: %{public}@", log: OSLog.default, type: .debug, "\(error)") - completionHandler(error) + s.status = .inactive + return } } }