Improve error mapping
This commit is contained in:
parent
a82c916ca9
commit
a39b675cc1
6 changed files with 16 additions and 24 deletions
|
|
@ -10,13 +10,12 @@ package io.element.android.features.login.impl.changeserver
|
||||||
import androidx.compose.ui.tooling.preview.PreviewParameterProvider
|
import androidx.compose.ui.tooling.preview.PreviewParameterProvider
|
||||||
import io.element.android.features.login.impl.error.ChangeServerError
|
import io.element.android.features.login.impl.error.ChangeServerError
|
||||||
import io.element.android.libraries.architecture.AsyncData
|
import io.element.android.libraries.architecture.AsyncData
|
||||||
import io.element.android.libraries.ui.strings.CommonStrings
|
|
||||||
|
|
||||||
open class ChangeServerStateProvider : PreviewParameterProvider<ChangeServerState> {
|
open class ChangeServerStateProvider : PreviewParameterProvider<ChangeServerState> {
|
||||||
override val values: Sequence<ChangeServerState>
|
override val values: Sequence<ChangeServerState>
|
||||||
get() = sequenceOf(
|
get() = sequenceOf(
|
||||||
aChangeServerState(),
|
aChangeServerState(),
|
||||||
aChangeServerState(changeServerAction = AsyncData.Failure(ChangeServerError.Error(CommonStrings.error_unknown))),
|
aChangeServerState(changeServerAction = AsyncData.Failure(ChangeServerError.Error(null))),
|
||||||
aChangeServerState(changeServerAction = AsyncData.Failure(ChangeServerError.SlidingSyncAlert)),
|
aChangeServerState(changeServerAction = AsyncData.Failure(ChangeServerError.SlidingSyncAlert)),
|
||||||
aChangeServerState(
|
aChangeServerState(
|
||||||
changeServerAction = AsyncData.Failure(
|
changeServerAction = AsyncData.Failure(
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,7 @@ import io.element.android.libraries.designsystem.components.dialogs.ErrorDialog
|
||||||
import io.element.android.libraries.designsystem.preview.ElementPreview
|
import io.element.android.libraries.designsystem.preview.ElementPreview
|
||||||
import io.element.android.libraries.designsystem.preview.PreviewsDayNight
|
import io.element.android.libraries.designsystem.preview.PreviewsDayNight
|
||||||
import io.element.android.libraries.designsystem.theme.LocalBuildMeta
|
import io.element.android.libraries.designsystem.theme.LocalBuildMeta
|
||||||
|
import io.element.android.libraries.ui.strings.CommonStrings
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun ChangeServerView(
|
fun ChangeServerView(
|
||||||
|
|
@ -58,7 +59,7 @@ fun ChangeServerView(
|
||||||
is ChangeServerError.Error -> {
|
is ChangeServerError.Error -> {
|
||||||
ErrorDialog(
|
ErrorDialog(
|
||||||
modifier = modifier,
|
modifier = modifier,
|
||||||
content = error.message(),
|
content = error.messageStr ?: stringResource(CommonStrings.error_unknown),
|
||||||
onSubmit = {
|
onSubmit = {
|
||||||
eventSink.invoke(ChangeServerEvents.ClearError)
|
eventSink.invoke(ChangeServerEvents.ClearError)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,23 +7,13 @@
|
||||||
|
|
||||||
package io.element.android.features.login.impl.error
|
package io.element.android.features.login.impl.error
|
||||||
|
|
||||||
import androidx.annotation.StringRes
|
|
||||||
import androidx.compose.runtime.Composable
|
|
||||||
import androidx.compose.runtime.ReadOnlyComposable
|
|
||||||
import androidx.compose.ui.res.stringResource
|
|
||||||
import io.element.android.features.login.impl.changeserver.AccountProviderAccessException
|
import io.element.android.features.login.impl.changeserver.AccountProviderAccessException
|
||||||
import io.element.android.libraries.matrix.api.auth.AuthenticationException
|
import io.element.android.libraries.matrix.api.auth.AuthenticationException
|
||||||
import io.element.android.libraries.ui.strings.CommonStrings
|
|
||||||
|
|
||||||
sealed class ChangeServerError : Exception() {
|
sealed class ChangeServerError : Exception() {
|
||||||
data class Error(
|
data class Error(
|
||||||
@StringRes val messageId: Int? = null,
|
|
||||||
val messageStr: String? = null,
|
val messageStr: String? = null,
|
||||||
) : ChangeServerError() {
|
) : ChangeServerError()
|
||||||
@Composable
|
|
||||||
@ReadOnlyComposable
|
|
||||||
fun message(): String = messageStr ?: stringResource(messageId ?: CommonStrings.error_unknown)
|
|
||||||
}
|
|
||||||
|
|
||||||
data class NeedElementPro(
|
data class NeedElementPro(
|
||||||
val unauthorisedAccountProviderTitle: String,
|
val unauthorisedAccountProviderTitle: String,
|
||||||
|
|
@ -52,7 +42,7 @@ sealed class ChangeServerError : Exception() {
|
||||||
unauthorisedAccountProviderTitle = error.unauthorisedAccountProviderTitle,
|
unauthorisedAccountProviderTitle = error.unauthorisedAccountProviderTitle,
|
||||||
authorisedAccountProviderTitles = error.authorisedAccountProviderTitles,
|
authorisedAccountProviderTitles = error.authorisedAccountProviderTitles,
|
||||||
)
|
)
|
||||||
else -> InvalidServer
|
else -> Error(messageStr = error.message)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -54,7 +54,7 @@ fun LoginModeView(
|
||||||
}
|
}
|
||||||
is ChangeServerError.Error -> {
|
is ChangeServerError.Error -> {
|
||||||
ErrorDialog(
|
ErrorDialog(
|
||||||
content = error.message(),
|
content = error.messageStr ?: stringResource(CommonStrings.error_unknown),
|
||||||
onSubmit = onClearError,
|
onSubmit = onClearError,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
@ -102,7 +102,7 @@ fun LoginModeView(
|
||||||
}
|
}
|
||||||
is AuthenticationException.AccountAlreadyLoggedIn -> {
|
is AuthenticationException.AccountAlreadyLoggedIn -> {
|
||||||
ErrorDialog(
|
ErrorDialog(
|
||||||
content = stringResource(CommonStrings.error_account_already_logged_in, error.message.orEmpty()),
|
content = stringResource(CommonStrings.error_account_already_logged_in, error.userId),
|
||||||
onSubmit = onClearError,
|
onSubmit = onClearError,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,10 +7,13 @@
|
||||||
|
|
||||||
package io.element.android.libraries.matrix.api.auth
|
package io.element.android.libraries.matrix.api.auth
|
||||||
|
|
||||||
sealed class AuthenticationException(message: String) : Exception(message) {
|
sealed class AuthenticationException(message: String?) : Exception(message) {
|
||||||
class AccountAlreadyLoggedIn(userId: String) : AuthenticationException(userId)
|
data class AccountAlreadyLoggedIn(
|
||||||
class InvalidServerName(message: String) : AuthenticationException(message)
|
val userId: String,
|
||||||
class SlidingSyncVersion(message: String) : AuthenticationException(message)
|
) : AuthenticationException(null)
|
||||||
class Oidc(message: String) : AuthenticationException(message)
|
|
||||||
class Generic(message: String) : AuthenticationException(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)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,6 @@ import org.matrix.rustcomponents.sdk.ClientBuildException
|
||||||
import org.matrix.rustcomponents.sdk.OidcException
|
import org.matrix.rustcomponents.sdk.OidcException
|
||||||
|
|
||||||
fun Throwable.mapAuthenticationException(): AuthenticationException {
|
fun Throwable.mapAuthenticationException(): AuthenticationException {
|
||||||
val message = this.message ?: "Unknown error"
|
|
||||||
return when (this) {
|
return when (this) {
|
||||||
is AuthenticationException -> this
|
is AuthenticationException -> this
|
||||||
is ClientBuildException -> when (this) {
|
is ClientBuildException -> when (this) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue