VPN: Better error messages

This commit is contained in:
Roopesh Chander 2018-10-30 00:24:50 +05:30
parent 0ef0eeb116
commit 495b017449
3 changed files with 27 additions and 5 deletions

View File

@ -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

View File

@ -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

View File

@ -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
}
}
}