From 6da33e22cc59337aecd9f4546c73ba8803aa31e7 Mon Sep 17 00:00:00 2001 From: Angelo Stavrow Date: Tue, 2 Feb 2021 11:12:30 -0500 Subject: [PATCH] Add logic for AccountError.invalidServerURL case when logging in --- Shared/Account/AccountLoginView.swift | 4 ++-- Shared/Account/AccountModel.swift | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/Shared/Account/AccountLoginView.swift b/Shared/Account/AccountLoginView.swift index 05d2384..d420aa1 100644 --- a/Shared/Account/AccountLoginView.swift +++ b/Shared/Account/AccountLoginView.swift @@ -62,7 +62,6 @@ struct AccountLoginView: View { if !(server.hasPrefix("https://") || server.hasPrefix("http://")) { server = "https://\(server)" } - print(server) // We only need the protocol and host from the URL, so drop anything else. let url = URLComponents(string: server) if let validURL = url { @@ -73,7 +72,8 @@ struct AccountLoginView: View { hostURL.host = host server = hostURL.string ?? server } else { - // TODO: - throw an error if this is an invalid URL. + model.loginErrorMessage = AccountError.invalidServerURL.localizedDescription + model.isPresentingLoginErrorAlert = true } model.login( to: URL(string: server)!, diff --git a/Shared/Account/AccountModel.swift b/Shared/Account/AccountModel.swift index 25683a5..0010a44 100644 --- a/Shared/Account/AccountModel.swift +++ b/Shared/Account/AccountModel.swift @@ -5,6 +5,7 @@ enum AccountError: Error { case invalidPassword case usernameNotFound case serverNotFound + case invalidServerURL } extension AccountError: LocalizedError { @@ -25,6 +26,11 @@ extension AccountError: LocalizedError { "Username not found. Did you use your email address by mistake?", comment: "" ) + case .invalidServerURL: + return NSLocalizedString( + "The server entered doesn't appear to be a valid URL. Please check what you've entered and try again.", + comment: "" + ) } } }