diff --git a/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/auth/AuthenticationException.kt b/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/auth/AuthenticationException.kt index 36af4113d2..ebe0c5e4e8 100644 --- a/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/auth/AuthenticationException.kt +++ b/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/auth/AuthenticationException.kt @@ -22,7 +22,10 @@ fun Throwable.mapAuthenticationException(): AuthenticationException { is ClientBuildException.Sdk -> AuthenticationException.Generic(message) is ClientBuildException.ServerUnreachable -> AuthenticationException.ServerUnreachable(message) is ClientBuildException.SlidingSync -> AuthenticationException.Generic(message) - is ClientBuildException.WellKnownDeserializationException -> AuthenticationException.Generic(message) + is ClientBuildException.WellKnownDeserializationException -> { + // Can happen if the .well-known URL has a redirection to an HTML page for instance + AuthenticationException.InvalidServerName(message) + } is ClientBuildException.WellKnownLookupFailed -> AuthenticationException.Generic(message) is ClientBuildException.EventCache -> AuthenticationException.Generic(message) } diff --git a/libraries/matrix/impl/src/test/kotlin/io/element/android/libraries/matrix/impl/auth/AuthenticationExceptionMappingTest.kt b/libraries/matrix/impl/src/test/kotlin/io/element/android/libraries/matrix/impl/auth/AuthenticationExceptionMappingTest.kt index a2425525bc..8449d9a6c3 100644 --- a/libraries/matrix/impl/src/test/kotlin/io/element/android/libraries/matrix/impl/auth/AuthenticationExceptionMappingTest.kt +++ b/libraries/matrix/impl/src/test/kotlin/io/element/android/libraries/matrix/impl/auth/AuthenticationExceptionMappingTest.kt @@ -30,6 +30,13 @@ class AuthenticationExceptionMappingTest { assertThat(mappedException).isException("Generic exception") } + @Test + fun `mapping a WellKnownDeserializationException returns a InvalidServerName AuthenticationException`() { + val exception = ClientBuildException.WellKnownDeserializationException("WellKnown Deserialization") + val mappedException = exception.mapAuthenticationException() + assertThat(mappedException).isException("WellKnown Deserialization") + } + @Test fun `mapping specific exceptions map to their kotlin counterparts`() { assertThat(ClientBuildException.Generic("Unknown error").mapAuthenticationException()) @@ -50,8 +57,6 @@ class AuthenticationExceptionMappingTest { .isException("Server unreachable") assertThat(ClientBuildException.SlidingSync("Sliding Sync").mapAuthenticationException()) .isException("Sliding Sync") - assertThat(ClientBuildException.WellKnownDeserializationException("WellKnown Deserialization").mapAuthenticationException()) - .isException("WellKnown Deserialization") assertThat(ClientBuildException.WellKnownLookupFailed("WellKnown Lookup Failed").mapAuthenticationException()) .isException("WellKnown Lookup Failed") assertThat(ClientBuildException.EventCache("EventCache error").mapAuthenticationException())