Add a couple more error messages during authentication. (#2497)

* Add copy for error when signing in with refresh tokens enabled.

* Show an error when a server's well-known file is invalid.

* Changelog.

* Fix wrong alert.
This commit is contained in:
Doug
2024-02-27 08:48:21 +00:00
committed by GitHub
parent 2cf427f715
commit 1afde10ce2
12 changed files with 36 additions and 3 deletions
@@ -112,8 +112,12 @@ final class LoginScreenCoordinator: CoordinatorProtocol {
viewModel.displayError(.alert(L10n.screenLoginErrorInvalidCredentials)) viewModel.displayError(.alert(L10n.screenLoginErrorInvalidCredentials))
case .accountDeactivated: case .accountDeactivated:
viewModel.displayError(.alert(L10n.screenLoginErrorDeactivatedAccount)) viewModel.displayError(.alert(L10n.screenLoginErrorDeactivatedAccount))
case .invalidWellKnown(let error):
viewModel.displayError(.invalidWellKnownAlert(error))
case .slidingSyncNotAvailable: case .slidingSyncNotAvailable:
viewModel.displayError(.slidingSyncAlert) viewModel.displayError(.slidingSyncAlert)
case .sessionTokenRefreshNotSupported:
viewModel.displayError(.refreshTokenAlert)
default: default:
viewModel.displayError(.alert(L10n.errorUnknown)) viewModel.displayError(.alert(L10n.errorUnknown))
} }
@@ -82,8 +82,12 @@ enum LoginScreenErrorType: Hashable {
case alert(String) case alert(String)
/// Looking up the homeserver from the username failed. /// Looking up the homeserver from the username failed.
case invalidHomeserver case invalidHomeserver
/// An alert that informs the user about a bad well-known file.
case invalidWellKnownAlert(String)
/// An alert that allows the user to learn about sliding sync. /// An alert that allows the user to learn about sliding sync.
case slidingSyncAlert case slidingSyncAlert
/// An alert that informs the user that login failed due to a refresh token being returned.
case refreshTokenAlert
/// The response from the homeserver was unexpected. /// The response from the homeserver was unexpected.
case unknown case unknown
} }
@@ -66,6 +66,10 @@ class LoginScreenViewModel: LoginScreenViewModelType, LoginScreenViewModelProtoc
state.bindings.alertInfo = AlertInfo(id: type, state.bindings.alertInfo = AlertInfo(id: type,
title: L10n.commonError, title: L10n.commonError,
message: L10n.screenLoginErrorInvalidUserId) message: L10n.screenLoginErrorInvalidUserId)
case .invalidWellKnownAlert(let error):
state.bindings.alertInfo = AlertInfo(id: .slidingSyncAlert,
title: L10n.commonServerNotSupported,
message: L10n.screenChangeServerErrorInvalidWellKnown(error))
case .slidingSyncAlert: case .slidingSyncAlert:
let openURL = { UIApplication.shared.open(self.slidingSyncLearnMoreURL) } let openURL = { UIApplication.shared.open(self.slidingSyncLearnMoreURL) }
state.bindings.alertInfo = AlertInfo(id: .slidingSyncAlert, state.bindings.alertInfo = AlertInfo(id: .slidingSyncAlert,
@@ -76,6 +80,10 @@ class LoginScreenViewModel: LoginScreenViewModelType, LoginScreenViewModelProtoc
// Clear out the invalid username to avoid an attempted login to matrix.org // Clear out the invalid username to avoid an attempted login to matrix.org
state.bindings.username = "" state.bindings.username = ""
case .refreshTokenAlert:
state.bindings.alertInfo = AlertInfo(id: type,
title: L10n.commonServerNotSupported,
message: L10n.screenLoginErrorRefreshTokens)
case .unknown: case .unknown:
state.bindings.alertInfo = AlertInfo(id: type) state.bindings.alertInfo = AlertInfo(id: type)
} }
@@ -111,6 +111,8 @@ final class ServerSelectionScreenCoordinator: CoordinatorProtocol {
switch error { switch error {
case .invalidServer, .invalidHomeserverAddress: case .invalidServer, .invalidHomeserverAddress:
viewModel.displayError(.footerMessage(L10n.screenChangeServerErrorInvalidHomeserver)) viewModel.displayError(.footerMessage(L10n.screenChangeServerErrorInvalidHomeserver))
case .invalidWellKnown(let error):
viewModel.displayError(.invalidWellKnownAlert(error))
case .slidingSyncNotAvailable: case .slidingSyncNotAvailable:
viewModel.displayError(.slidingSyncAlert) viewModel.displayError(.slidingSyncAlert)
default: default:
@@ -87,6 +87,8 @@ enum ServerSelectionScreenViewAction {
enum ServerSelectionScreenErrorType: Hashable { enum ServerSelectionScreenErrorType: Hashable {
/// An error message to be shown in the text field footer. /// An error message to be shown in the text field footer.
case footerMessage(String) case footerMessage(String)
/// An alert that informs the user about a bad well-known file.
case invalidWellKnownAlert(String)
/// An alert that allows the user to learn about sliding sync. /// An alert that allows the user to learn about sliding sync.
case slidingSyncAlert case slidingSyncAlert
} }
@@ -54,6 +54,10 @@ class ServerSelectionScreenViewModel: ServerSelectionScreenViewModelType, Server
withElementAnimation { withElementAnimation {
state.footerErrorMessage = message state.footerErrorMessage = message
} }
case .invalidWellKnownAlert(let error):
state.bindings.alertInfo = AlertInfo(id: .slidingSyncAlert,
title: L10n.commonServerNotSupported,
message: L10n.screenChangeServerErrorInvalidWellKnown(error))
case .slidingSyncAlert: case .slidingSyncAlert:
let openURL = { UIApplication.shared.open(self.slidingSyncLearnMoreURL) } let openURL = { UIApplication.shared.open(self.slidingSyncLearnMoreURL) }
state.bindings.alertInfo = AlertInfo(id: .slidingSyncAlert, state.bindings.alertInfo = AlertInfo(id: .slidingSyncAlert,
@@ -187,9 +187,7 @@ final class SoftLogoutScreenCoordinator: CoordinatorProtocol {
// No need to show an error, the user cancelled authentication. // No need to show an error, the user cancelled authentication.
break break
case .sessionTokenRefreshNotSupported: case .sessionTokenRefreshNotSupported:
// We should display a specific error saying that we do not support this kind of login viewModel.displayError(.refreshTokenAlert)
// But the copy is TBD
viewModel.displayError(.alert(L10n.errorUnknown))
default: default:
viewModel.displayError(.alert(L10n.errorUnknown)) viewModel.displayError(.alert(L10n.errorUnknown))
} }
@@ -101,6 +101,8 @@ enum SoftLogoutScreenViewAction {
enum SoftLogoutScreenErrorType: Hashable { enum SoftLogoutScreenErrorType: Hashable {
/// A specific error message shown in an alert. /// A specific error message shown in an alert.
case alert(String) case alert(String)
/// An alert that informs the user that login failed due to a refresh token being returned.
case refreshTokenAlert
/// An unknown error occurred. /// An unknown error occurred.
case unknown case unknown
} }
@@ -60,6 +60,10 @@ class SoftLogoutScreenViewModel: SoftLogoutScreenViewModelType, SoftLogoutScreen
state.bindings.alertInfo = AlertInfo(id: type, state.bindings.alertInfo = AlertInfo(id: type,
title: L10n.commonError, title: L10n.commonError,
message: message) message: message)
case .refreshTokenAlert:
state.bindings.alertInfo = AlertInfo(id: type,
title: L10n.commonServerNotSupported,
message: L10n.screenLoginErrorRefreshTokens)
case .unknown: case .unknown:
state.bindings.alertInfo = AlertInfo(id: type) state.bindings.alertInfo = AlertInfo(id: type)
} }
@@ -80,6 +80,9 @@ class AuthenticationServiceProxy: AuthenticationServiceProxyProtocol {
homeserverSubject.send(homeserver) homeserverSubject.send(homeserver)
return .success(()) return .success(())
} catch AuthenticationError.WellKnownDeserializationError(let error) {
MXLog.error("The user entered a server with an invalid well-known file: \(error)")
return .failure(.invalidWellKnown(error))
} catch AuthenticationError.SlidingSyncNotAvailable { } catch AuthenticationError.SlidingSyncNotAvailable {
MXLog.info("User entered a homeserver that isn't configured for sliding sync.") MXLog.info("User entered a homeserver that isn't configured for sliding sync.")
return .failure(.slidingSyncNotAvailable) return .failure(.slidingSyncNotAvailable)
@@ -31,6 +31,7 @@ enum AuthenticationServiceError: Error {
case invalidServer case invalidServer
case invalidCredentials case invalidCredentials
case invalidHomeserverAddress case invalidHomeserverAddress
case invalidWellKnown(String)
case slidingSyncNotAvailable case slidingSyncNotAvailable
case accountDeactivated case accountDeactivated
case failedLoggingIn case failedLoggingIn
+1
View File
@@ -0,0 +1 @@
Add error messages about refresh tokens and an invalid well-known file.