diff options
author | 2018-12-06 19:05:46 +0530 | |
---|---|---|
committer | 2018-12-07 12:36:19 +0530 | |
commit | dcfa9473e955e372d2c32d7fc682a6fa9ff30bdf (patch) | |
tree | dfc481407b9b650076635fbe52e7f9f65dbcdd47 /WireGuard/WireGuard/ZipArchive/ZipExporter.swift | |
parent | Error handling: Introduce a WireGuardResult type to handle errors in callbacks across the app (diff) | |
download | wireguard-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/ZipArchive/ZipExporter.swift')
-rw-r--r-- | WireGuard/WireGuard/ZipArchive/ZipExporter.swift | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/WireGuard/WireGuard/ZipArchive/ZipExporter.swift b/WireGuard/WireGuard/ZipArchive/ZipExporter.swift index bd6c3dd..a4e9d7a 100644 --- a/WireGuard/WireGuard/ZipArchive/ZipExporter.swift +++ b/WireGuard/WireGuard/ZipArchive/ZipExporter.swift @@ -3,12 +3,20 @@ import UIKit -enum ZipExporterError: Error { +enum ZipExporterError: WireGuardAppError { case noTunnelsToExport + + func alertText() -> (String, String) { + switch (self) { + case .noTunnelsToExport: + return ("Nothing to export", "There are no tunnels to export") + } + } } class ZipExporter { - static func exportConfigFiles(tunnelConfigurations: [TunnelConfiguration], to url: URL, completion: @escaping (Error?) -> Void) { + static func exportConfigFiles(tunnelConfigurations: [TunnelConfiguration], to url: URL, + completion: @escaping (WireGuardAppError?) -> Void) { guard (!tunnelConfigurations.isEmpty) else { completion(ZipExporterError.noTunnelsToExport) @@ -27,9 +35,11 @@ class ZipExporter { } do { try ZipArchive.archive(inputs: inputsToArchiver, to: url) - } catch (let e) { - DispatchQueue.main.async { completion(e) } + } catch (let error as WireGuardAppError) { + DispatchQueue.main.async { completion(error) } return + } catch { + fatalError() } DispatchQueue.main.async { completion(nil) } } |