Skip to content

Commit e882fc7

Browse files
authored
Merge pull request #6370 from element-hq/feature/bma/fixMalformedWellknown
Improve error displayed when .well-known file is malformed
2 parents 05c9a82 + b2d6e8c commit e882fc7

2 files changed

Lines changed: 11 additions & 3 deletions

File tree

libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/auth/AuthenticationException.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ fun Throwable.mapAuthenticationException(): AuthenticationException {
2222
is ClientBuildException.Sdk -> AuthenticationException.Generic(message)
2323
is ClientBuildException.ServerUnreachable -> AuthenticationException.ServerUnreachable(message)
2424
is ClientBuildException.SlidingSync -> AuthenticationException.Generic(message)
25-
is ClientBuildException.WellKnownDeserializationException -> AuthenticationException.Generic(message)
25+
is ClientBuildException.WellKnownDeserializationException -> {
26+
// Can happen if the .well-known URL has a redirection to an HTML page for instance
27+
AuthenticationException.InvalidServerName(message)
28+
}
2629
is ClientBuildException.WellKnownLookupFailed -> AuthenticationException.Generic(message)
2730
is ClientBuildException.EventCache -> AuthenticationException.Generic(message)
2831
}

libraries/matrix/impl/src/test/kotlin/io/element/android/libraries/matrix/impl/auth/AuthenticationExceptionMappingTest.kt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@ class AuthenticationExceptionMappingTest {
3030
assertThat(mappedException).isException<AuthenticationException.Generic>("Generic exception")
3131
}
3232

33+
@Test
34+
fun `mapping a WellKnownDeserializationException returns a InvalidServerName AuthenticationException`() {
35+
val exception = ClientBuildException.WellKnownDeserializationException("WellKnown Deserialization")
36+
val mappedException = exception.mapAuthenticationException()
37+
assertThat(mappedException).isException<AuthenticationException.InvalidServerName>("WellKnown Deserialization")
38+
}
39+
3340
@Test
3441
fun `mapping specific exceptions map to their kotlin counterparts`() {
3542
assertThat(ClientBuildException.Generic("Unknown error").mapAuthenticationException())
@@ -50,8 +57,6 @@ class AuthenticationExceptionMappingTest {
5057
.isException<AuthenticationException.ServerUnreachable>("Server unreachable")
5158
assertThat(ClientBuildException.SlidingSync("Sliding Sync").mapAuthenticationException())
5259
.isException<AuthenticationException.Generic>("Sliding Sync")
53-
assertThat(ClientBuildException.WellKnownDeserializationException("WellKnown Deserialization").mapAuthenticationException())
54-
.isException<AuthenticationException.Generic>("WellKnown Deserialization")
5560
assertThat(ClientBuildException.WellKnownLookupFailed("WellKnown Lookup Failed").mapAuthenticationException())
5661
.isException<AuthenticationException.Generic>("WellKnown Lookup Failed")
5762
assertThat(ClientBuildException.EventCache("EventCache error").mapAuthenticationException())

0 commit comments

Comments
 (0)