aboutsummaryrefslogtreecommitdiffstats
path: root/WireGuard/WireGuard/UI/iOS
diff options
context:
space:
mode:
authorRoopesh Chander <roop@roopc.net>2018-12-06 19:05:46 +0530
committerRoopesh Chander <roop@roopc.net>2018-12-07 12:36:19 +0530
commitdcfa9473e955e372d2c32d7fc682a6fa9ff30bdf (patch)
treedfc481407b9b650076635fbe52e7f9f65dbcdd47 /WireGuard/WireGuard/UI/iOS
parentError handling: Introduce a WireGuardResult type to handle errors in callbacks across the app (diff)
downloadwireguard-apple-dcfa9473e955e372d2c32d7fc682a6fa9ff30bdf.tar.xz
wireguard-apple-dcfa9473e955e372d2c32d7fc682a6fa9ff30bdf.zip
Error handling: Use WireGuardAppError and WireGuardResult throughout the app
Signed-off-by: Roopesh Chander <roop@roopc.net>
Diffstat (limited to 'WireGuard/WireGuard/UI/iOS')
-rw-r--r--WireGuard/WireGuard/UI/iOS/ErrorPresenter.swift31
-rw-r--r--WireGuard/WireGuard/UI/iOS/TunnelsListTableViewController.swift5
2 files changed, 5 insertions, 31 deletions
diff --git a/WireGuard/WireGuard/UI/iOS/ErrorPresenter.swift b/WireGuard/WireGuard/UI/iOS/ErrorPresenter.swift
index b085b97..3c4a1bf 100644
--- a/WireGuard/WireGuard/UI/iOS/ErrorPresenter.swift
+++ b/WireGuard/WireGuard/UI/iOS/ErrorPresenter.swift
@@ -5,37 +5,10 @@ import UIKit
import os.log
class ErrorPresenter {
- static func errorMessage(for error: Error) -> (String, String) {
-
- if let error = error as? WireGuardAppError {
- return error.alertText()
- }
-
- switch (error) {
-
- // Importing a zip file
- case ZipArchiveError.cantOpenInputZipFile:
- return ("Unable to read zip archive", "The zip archive could not be read.")
- case ZipArchiveError.badArchive:
- return ("Unable to read zip archive", "Bad or corrupt zip archive.")
- case ZipImporterError.noTunnelsInZipArchive:
- return ("No tunnels in zip archive", "No .conf tunnel files were found inside the zip archive.")
-
- // Exporting a zip file
- case ZipArchiveError.cantOpenOutputZipFileForWriting:
- return ("Unable to create zip archive", "Could not create a zip file in the app's document directory.")
- case ZipExporterError.noTunnelsToExport:
- return ("Nothing to export", "There are no tunnels to export")
-
- default:
- return ("Error", error.localizedDescription)
- }
- }
-
- static func showErrorAlert(error: Error, from sourceVC: UIViewController?,
+ static func showErrorAlert(error: WireGuardAppError, from sourceVC: UIViewController?,
onDismissal: (() -> Void)? = nil, onPresented: (() -> Void)? = nil) {
guard let sourceVC = sourceVC else { return }
- let (title, message) = ErrorPresenter.errorMessage(for: error)
+ let (title, message) = error.alertText()
let okAction = UIAlertAction(title: "OK", style: .default) { (_) in
onDismissal?()
}
diff --git a/WireGuard/WireGuard/UI/iOS/TunnelsListTableViewController.swift b/WireGuard/WireGuard/UI/iOS/TunnelsListTableViewController.swift
index ae39587..4450796 100644
--- a/WireGuard/WireGuard/UI/iOS/TunnelsListTableViewController.swift
+++ b/WireGuard/WireGuard/UI/iOS/TunnelsListTableViewController.swift
@@ -165,11 +165,12 @@ class TunnelsListTableViewController: UIViewController {
func importFromFile(url: URL) {
guard let tunnelsManager = tunnelsManager else { return }
if (url.pathExtension == "zip") {
- ZipImporter.importConfigFiles(from: url) { (configs, error) in
- if let error = error {
+ ZipImporter.importConfigFiles(from: url) { [weak self] result in
+ if let error = result.error {
ErrorPresenter.showErrorAlert(error: error, from: self)
return
}
+ let configs: [TunnelConfiguration?] = result.value!
tunnelsManager.addMultiple(tunnelConfigurations: configs.compactMap { $0 }) { [weak self] (numberSuccessful) in
if numberSuccessful == configs.count {
return