Error handling: Use ErrorPresenter.showErrorAlert() instead of per-VC showErrorAlert() methods
Signed-off-by: Roopesh Chander <roop@roopc.net>
This commit is contained in:
parent
dcfa9473e9
commit
c827a00307
|
@ -101,14 +101,14 @@ class SettingsTableViewController: UITableViewController {
|
||||||
if (FileManager.default.fileExists(atPath: destinationURL.path)) {
|
if (FileManager.default.fileExists(atPath: destinationURL.path)) {
|
||||||
let isDeleted = FileManager.deleteFile(at: destinationURL)
|
let isDeleted = FileManager.deleteFile(at: destinationURL)
|
||||||
if (!isDeleted) {
|
if (!isDeleted) {
|
||||||
showErrorAlert(title: "No log available", message: "The pre-existing log could not be cleared")
|
ErrorPresenter.showErrorAlert(title: "No log available", message: "The pre-existing log could not be cleared", from: self)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
guard let networkExtensionLogFileURL = FileManager.networkExtensionLogFileURL,
|
guard let networkExtensionLogFileURL = FileManager.networkExtensionLogFileURL,
|
||||||
FileManager.default.fileExists(atPath: networkExtensionLogFileURL.path) else {
|
FileManager.default.fileExists(atPath: networkExtensionLogFileURL.path) else {
|
||||||
showErrorAlert(title: "No log available", message: "Please activate a tunnel and then export the log")
|
ErrorPresenter.showErrorAlert(title: "No log available", message: "Please activate a tunnel and then export the log", from: self)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -116,7 +116,7 @@ class SettingsTableViewController: UITableViewController {
|
||||||
try FileManager.default.copyItem(at: networkExtensionLogFileURL, to: destinationURL)
|
try FileManager.default.copyItem(at: networkExtensionLogFileURL, to: destinationURL)
|
||||||
} catch {
|
} catch {
|
||||||
os_log("Failed to copy file: %{public}@ to %{public}@: %{public}@", log: OSLog.default, type: .error, networkExtensionLogFileURL.absoluteString, destinationURL.absoluteString, error.localizedDescription)
|
os_log("Failed to copy file: %{public}@ to %{public}@: %{public}@", log: OSLog.default, type: .error, networkExtensionLogFileURL.absoluteString, destinationURL.absoluteString, error.localizedDescription)
|
||||||
showErrorAlert(title: "No log available", message: "The log could not be accessed")
|
ErrorPresenter.showErrorAlert(title: "No log available", message: "The log could not be accessed", from: self)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -130,14 +130,6 @@ class SettingsTableViewController: UITableViewController {
|
||||||
}
|
}
|
||||||
self.present(activityVC, animated: true)
|
self.present(activityVC, animated: true)
|
||||||
}
|
}
|
||||||
|
|
||||||
func showErrorAlert(title: String, message: String) {
|
|
||||||
let okAction = UIAlertAction(title: "OK", style: .default)
|
|
||||||
let alert = UIAlertController(title: title, message: message, preferredStyle: .alert)
|
|
||||||
alert.addAction(okAction)
|
|
||||||
|
|
||||||
self.present(alert, animated: true, completion: nil)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: UITableViewDataSource
|
// MARK: UITableViewDataSource
|
||||||
|
|
|
@ -53,14 +53,6 @@ class TunnelDetailTableViewController: UITableViewController {
|
||||||
present(editNC, animated: true)
|
present(editNC, animated: true)
|
||||||
}
|
}
|
||||||
|
|
||||||
func showErrorAlert(title: String, message: String) {
|
|
||||||
let okAction = UIAlertAction(title: "OK", style: .default)
|
|
||||||
let alert = UIAlertController(title: title, message: message, preferredStyle: .alert)
|
|
||||||
alert.addAction(okAction)
|
|
||||||
|
|
||||||
self.present(alert, animated: true, completion: nil)
|
|
||||||
}
|
|
||||||
|
|
||||||
func showConfirmationAlert(message: String, buttonTitle: String, from sourceView: UIView,
|
func showConfirmationAlert(message: String, buttonTitle: String, from sourceView: UIView,
|
||||||
onConfirmed: @escaping (() -> Void)) {
|
onConfirmed: @escaping (() -> Void)) {
|
||||||
let destroyAction = UIAlertAction(title: buttonTitle, style: .destructive) { (_) in
|
let destroyAction = UIAlertAction(title: buttonTitle, style: .destructive) { (_) in
|
||||||
|
|
|
@ -116,14 +116,6 @@ class TunnelEditTableViewController: UITableViewController {
|
||||||
dismiss(animated: true, completion: nil)
|
dismiss(animated: true, completion: nil)
|
||||||
self.delegate?.tunnelEditingCancelled()
|
self.delegate?.tunnelEditingCancelled()
|
||||||
}
|
}
|
||||||
|
|
||||||
func showErrorAlert(title: String, message: String) {
|
|
||||||
let okAction = UIAlertAction(title: "OK", style: .default)
|
|
||||||
let alert = UIAlertController(title: title, message: message, preferredStyle: .alert)
|
|
||||||
alert.addAction(okAction)
|
|
||||||
|
|
||||||
self.present(alert, animated: true, completion: nil)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: UITableViewDataSource
|
// MARK: UITableViewDataSource
|
||||||
|
|
|
@ -154,14 +154,6 @@ class TunnelsListTableViewController: UIViewController {
|
||||||
self.present(scanQRCodeNC, animated: true)
|
self.present(scanQRCodeNC, animated: true)
|
||||||
}
|
}
|
||||||
|
|
||||||
func showErrorAlert(title: String, message: String) {
|
|
||||||
let okAction = UIAlertAction(title: "OK", style: .default)
|
|
||||||
let alert = UIAlertController(title: title, message: message, preferredStyle: .alert)
|
|
||||||
alert.addAction(okAction)
|
|
||||||
|
|
||||||
self.present(alert, animated: true, completion: nil)
|
|
||||||
}
|
|
||||||
|
|
||||||
func importFromFile(url: URL) {
|
func importFromFile(url: URL) {
|
||||||
guard let tunnelsManager = tunnelsManager else { return }
|
guard let tunnelsManager = tunnelsManager else { return }
|
||||||
if (url.pathExtension == "zip") {
|
if (url.pathExtension == "zip") {
|
||||||
|
@ -175,8 +167,9 @@ class TunnelsListTableViewController: UIViewController {
|
||||||
if numberSuccessful == configs.count {
|
if numberSuccessful == configs.count {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
self?.showErrorAlert(title: "Created \(numberSuccessful) tunnels",
|
ErrorPresenter.showErrorAlert(title: "Created \(numberSuccessful) tunnels",
|
||||||
message: "Created \(numberSuccessful) of \(configs.count) tunnels from zip archive")
|
message: "Created \(numberSuccessful) of \(configs.count) tunnels from zip archive",
|
||||||
|
from: self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else /* if (url.pathExtension == "conf") -- we assume everything else is a conf */ {
|
} else /* if (url.pathExtension == "conf") -- we assume everything else is a conf */ {
|
||||||
|
@ -189,7 +182,9 @@ class TunnelsListTableViewController: UIViewController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
showErrorAlert(title: "Unable to import tunnel", message: "An error occured when importing the tunnel configuration.")
|
ErrorPresenter.showErrorAlert(title: "Unable to import tunnel",
|
||||||
|
message: "An error occured when importing the tunnel configuration.",
|
||||||
|
from: self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue