Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,24 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.res.stringResource
import io.element.android.features.login.impl.R
import io.element.android.libraries.matrix.api.auth.AuthenticationException
import io.element.android.libraries.ui.strings.CommonStrings

sealed class ChangeServerError : Throwable() {
data class Error(@StringRes val messageId: Int) : ChangeServerError() {
data class Error(
@StringRes val messageId: Int? = null,
val messageStr: String? = null,
) : ChangeServerError() {
@Composable
fun message(): String = stringResource(messageId)
fun message(): String = messageStr ?: stringResource(messageId ?: CommonStrings.error_unknown)
}

data object SlidingSyncAlert : ChangeServerError()

companion object {
fun from(error: Throwable): ChangeServerError = when (error) {
is AuthenticationException.SlidingSyncVersion -> SlidingSyncAlert
else -> Error(R.string.screen_change_server_error_invalid_homeserver)
is AuthenticationException.Oidc -> Error(messageStr = error.message)
else -> Error(messageId = R.string.screen_change_server_error_invalid_homeserver)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ package io.element.android.libraries.matrix.api.auth
sealed class AuthenticationException(message: String) : Exception(message) {
class InvalidServerName(message: String) : AuthenticationException(message)
class SlidingSyncVersion(message: String) : AuthenticationException(message)
class Oidc(message: String) : AuthenticationException(message)
class Generic(message: String) : AuthenticationException(message)
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ package io.element.android.libraries.matrix.impl.auth

import io.element.android.libraries.matrix.api.auth.AuthenticationException
import org.matrix.rustcomponents.sdk.ClientBuildException
import org.matrix.rustcomponents.sdk.OidcException

fun Throwable.mapAuthenticationException(): AuthenticationException {
val message = this.message ?: "Unknown error"
Expand All @@ -24,6 +25,13 @@ fun Throwable.mapAuthenticationException(): AuthenticationException {
is ClientBuildException.WellKnownLookupFailed -> AuthenticationException.Generic(message)
is ClientBuildException.EventCache -> AuthenticationException.Generic(message)
}
is OidcException -> when (this) {
is OidcException.Generic -> AuthenticationException.Oidc(message)
is OidcException.CallbackUrlInvalid -> AuthenticationException.Oidc(message)
is OidcException.Cancelled -> AuthenticationException.Oidc(message)
is OidcException.MetadataInvalid -> AuthenticationException.Oidc(message)
is OidcException.NotSupported -> AuthenticationException.Oidc(message)
}
Comment on lines +28 to +34
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we're mapping them to the same type, are we sure the messages are clear enough to track the root cause of the issue?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, for what I have seen, it seems to be clear enough. We may want to improve the mapping if it's not the case.

Previously the homeserver reachability was designed as the cause of the failure, so I guess this is already much better.

else -> AuthenticationException.Generic(message)
}
}