Add logic for AccountError.invalidServerURL case when logging in

This commit is contained in:
Angelo Stavrow 2021-02-02 11:12:30 -05:00
parent 1a8951a3e0
commit 6da33e22cc
No known key found for this signature in database
GPG Key ID: 1A49C7064E060EEE
2 changed files with 8 additions and 2 deletions

View File

@ -62,7 +62,6 @@ struct AccountLoginView: View {
if !(server.hasPrefix("https://") || server.hasPrefix("http://")) { if !(server.hasPrefix("https://") || server.hasPrefix("http://")) {
server = "https://\(server)" server = "https://\(server)"
} }
print(server)
// We only need the protocol and host from the URL, so drop anything else. // We only need the protocol and host from the URL, so drop anything else.
let url = URLComponents(string: server) let url = URLComponents(string: server)
if let validURL = url { if let validURL = url {
@ -73,7 +72,8 @@ struct AccountLoginView: View {
hostURL.host = host hostURL.host = host
server = hostURL.string ?? server server = hostURL.string ?? server
} else { } else {
// TODO: - throw an error if this is an invalid URL. model.loginErrorMessage = AccountError.invalidServerURL.localizedDescription
model.isPresentingLoginErrorAlert = true
} }
model.login( model.login(
to: URL(string: server)!, to: URL(string: server)!,

View File

@ -5,6 +5,7 @@ enum AccountError: Error {
case invalidPassword case invalidPassword
case usernameNotFound case usernameNotFound
case serverNotFound case serverNotFound
case invalidServerURL
} }
extension AccountError: LocalizedError { extension AccountError: LocalizedError {
@ -25,6 +26,11 @@ extension AccountError: LocalizedError {
"Username not found. Did you use your email address by mistake?", "Username not found. Did you use your email address by mistake?",
comment: "" 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: ""
)
} }
} }
} }