summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAndrej Mihajlov <and@mullvad.net>2020-01-07 13:08:28 +0100
committerAndrej Mihajlov <and@mullvad.net>2020-01-08 15:02:46 +0100
commit501064962e47f84709675b49a9c392fbf73bf879 (patch)
treec4e440bcf05f9413b11ccd76e47c1ccd7cffc10d
parentdf86ac696599630f98d6f26bf7b901e3f8ab07e4 (diff)
downloadmullvadvpn-501064962e47f84709675b49a9c392fbf73bf879.tar.xz
mullvadvpn-501064962e47f84709675b49a9c392fbf73bf879.zip
Implement LocalizedError for TunnelManagerError
-rw-r--r--ios/MullvadVPN/TunnelManager.swift60
1 files changed, 60 insertions, 0 deletions
diff --git a/ios/MullvadVPN/TunnelManager.swift b/ios/MullvadVPN/TunnelManager.swift
index f1b0ab8c59..3019fd2343 100644
--- a/ios/MullvadVPN/TunnelManager.swift
+++ b/ios/MullvadVPN/TunnelManager.swift
@@ -41,6 +41,66 @@ enum TunnelManagerError: Error {
case regenerateWireguardPrivateKey(RegenerateWireguardPrivateKeyError)
}
+extension TunnelManagerError: LocalizedError {
+
+ var errorDescription: String? {
+ switch self {
+ case .regenerateWireguardPrivateKey:
+ return NSLocalizedString("Cannot regenerate the private key", comment: "")
+
+ case .setAccount:
+ return NSLocalizedString("Cannot set up the tunnel", comment: "")
+
+ case .getWireguardPublicKey:
+ return NSLocalizedString("Cannot retrieve the public key", comment: "")
+
+ case .startTunnel:
+ return NSLocalizedString("Cannot start the tunnel", comment: "")
+
+ default:
+ return nil
+ }
+ }
+
+ var failureReason: String? {
+ switch self {
+
+ case .setAccount(.pushWireguardKey(let pushError)),
+ .regenerateWireguardPrivateKey(.replaceWireguardKey(let pushError)):
+ switch pushError {
+ case .transport(.network(let urlError)):
+ return urlError.localizedDescription
+
+ case .server(let serverError):
+ return serverError.errorDescription
+
+ default:
+ return NSLocalizedString("Internal error", comment: "")
+ }
+
+ default:
+ return nil
+ }
+ }
+
+ var recoverySuggestion: String? {
+ switch self {
+ case .regenerateWireguardPrivateKey(.replaceWireguardKey(let pushError)):
+ switch pushError {
+ case .server(let serverError) where serverError.code == .tooManyWireguardKeys:
+ return NSLocalizedString("Remove unused WireGuard keys and try again.", comment: "")
+
+ default:
+ return nil
+ }
+
+ default:
+ return nil
+ }
+ }
+
+}
+
enum TunnelIpcRequestError: Error {
/// IPC is not set yet
case missingIpc