mirror of
https://github.com/Novaloop-AG/element-x-android.git
synced 2026-11-03 06:55:41 +00:00
Improve error mapping
This commit is contained in:
+11
-2
@@ -32,8 +32,17 @@ sealed class ChangeServerError : Exception() {
|
|||||||
companion object {
|
companion object {
|
||||||
fun from(error: Throwable): ChangeServerError = when (error) {
|
fun from(error: Throwable): ChangeServerError = when (error) {
|
||||||
is ChangeServerError -> error
|
is ChangeServerError -> error
|
||||||
is AuthenticationException.SlidingSyncVersion -> SlidingSyncAlert
|
is AuthenticationException -> {
|
||||||
is AuthenticationException.Oidc -> Error(messageStr = error.message)
|
when (error) {
|
||||||
|
is AuthenticationException.SlidingSyncVersion -> SlidingSyncAlert
|
||||||
|
is AuthenticationException.InvalidServerName,
|
||||||
|
is AuthenticationException.ServerUnreachable -> InvalidServer
|
||||||
|
// AccountAlreadyLoggedIn error should not happen at this point
|
||||||
|
is AuthenticationException.AccountAlreadyLoggedIn -> Error(messageStr = error.message)
|
||||||
|
is AuthenticationException.Generic -> Error(messageStr = error.message)
|
||||||
|
is AuthenticationException.Oidc -> Error(messageStr = error.message)
|
||||||
|
}
|
||||||
|
}
|
||||||
is AccountProviderAccessException.NeedElementProException -> NeedElementPro(
|
is AccountProviderAccessException.NeedElementProException -> NeedElementPro(
|
||||||
unauthorisedAccountProviderTitle = error.unauthorisedAccountProviderTitle,
|
unauthorisedAccountProviderTitle = error.unauthorisedAccountProviderTitle,
|
||||||
applicationId = error.applicationId,
|
applicationId = error.applicationId,
|
||||||
|
|||||||
+1
@@ -14,6 +14,7 @@ sealed class AuthenticationException(message: String?) : Exception(message) {
|
|||||||
|
|
||||||
class InvalidServerName(message: String?) : AuthenticationException(message)
|
class InvalidServerName(message: String?) : AuthenticationException(message)
|
||||||
class SlidingSyncVersion(message: String?) : AuthenticationException(message)
|
class SlidingSyncVersion(message: String?) : AuthenticationException(message)
|
||||||
|
class ServerUnreachable(message: String?) : AuthenticationException(message)
|
||||||
class Oidc(message: String?) : AuthenticationException(message)
|
class Oidc(message: String?) : AuthenticationException(message)
|
||||||
class Generic(message: String?) : AuthenticationException(message)
|
class Generic(message: String?) : AuthenticationException(message)
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -19,7 +19,7 @@ fun Throwable.mapAuthenticationException(): AuthenticationException {
|
|||||||
is ClientBuildException.InvalidServerName -> AuthenticationException.InvalidServerName(message)
|
is ClientBuildException.InvalidServerName -> AuthenticationException.InvalidServerName(message)
|
||||||
is ClientBuildException.SlidingSyncVersion -> AuthenticationException.SlidingSyncVersion(message)
|
is ClientBuildException.SlidingSyncVersion -> AuthenticationException.SlidingSyncVersion(message)
|
||||||
is ClientBuildException.Sdk -> AuthenticationException.Generic(message)
|
is ClientBuildException.Sdk -> AuthenticationException.Generic(message)
|
||||||
is ClientBuildException.ServerUnreachable -> AuthenticationException.Generic(message)
|
is ClientBuildException.ServerUnreachable -> AuthenticationException.ServerUnreachable(message)
|
||||||
is ClientBuildException.SlidingSync -> AuthenticationException.Generic(message)
|
is ClientBuildException.SlidingSync -> AuthenticationException.Generic(message)
|
||||||
is ClientBuildException.WellKnownDeserializationException -> AuthenticationException.Generic(message)
|
is ClientBuildException.WellKnownDeserializationException -> AuthenticationException.Generic(message)
|
||||||
is ClientBuildException.WellKnownLookupFailed -> AuthenticationException.Generic(message)
|
is ClientBuildException.WellKnownLookupFailed -> AuthenticationException.Generic(message)
|
||||||
|
|||||||
+3
-3
@@ -16,10 +16,10 @@ import org.matrix.rustcomponents.sdk.OidcException
|
|||||||
|
|
||||||
class AuthenticationExceptionMappingTest {
|
class AuthenticationExceptionMappingTest {
|
||||||
@Test
|
@Test
|
||||||
fun `mapping an exception with no message returns 'Unknown error' message`() {
|
fun `mapping an exception with no message returns null message`() {
|
||||||
val exception = Exception()
|
val exception = Exception()
|
||||||
val mappedException = exception.mapAuthenticationException()
|
val mappedException = exception.mapAuthenticationException()
|
||||||
assertThat(mappedException.message).isEqualTo("Unknown error")
|
assertThat(mappedException.message).isEqualTo(null)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -46,7 +46,7 @@ class AuthenticationExceptionMappingTest {
|
|||||||
assertThat(ClientBuildException.Sdk("SDK issue").mapAuthenticationException())
|
assertThat(ClientBuildException.Sdk("SDK issue").mapAuthenticationException())
|
||||||
.isException<AuthenticationException.Generic>("SDK issue")
|
.isException<AuthenticationException.Generic>("SDK issue")
|
||||||
assertThat(ClientBuildException.ServerUnreachable("Server unreachable").mapAuthenticationException())
|
assertThat(ClientBuildException.ServerUnreachable("Server unreachable").mapAuthenticationException())
|
||||||
.isException<AuthenticationException.Generic>("Server unreachable")
|
.isException<AuthenticationException.ServerUnreachable>("Server unreachable")
|
||||||
assertThat(ClientBuildException.SlidingSync("Sliding Sync").mapAuthenticationException())
|
assertThat(ClientBuildException.SlidingSync("Sliding Sync").mapAuthenticationException())
|
||||||
.isException<AuthenticationException.Generic>("Sliding Sync")
|
.isException<AuthenticationException.Generic>("Sliding Sync")
|
||||||
assertThat(ClientBuildException.WellKnownDeserializationException("WellKnown Deserialization").mapAuthenticationException())
|
assertThat(ClientBuildException.WellKnownDeserializationException("WellKnown Deserialization").mapAuthenticationException())
|
||||||
|
|||||||
Reference in New Issue
Block a user