allowing the profile call to continue when receiving a 404 instead of crashing
- this case is known by the spec for when a profile doesn't exist yet - 403s still crash as fetching your own profile information should never result in access denied
This commit is contained in:
parent
9d4f0f4197
commit
1d1aff0ca9
|
@ -5,6 +5,8 @@ import app.dapk.st.matrix.common.*
|
|||
import app.dapk.st.matrix.http.MatrixHttpClient
|
||||
import app.dapk.st.matrix.room.ProfileService
|
||||
import app.dapk.st.matrix.room.ProfileStore
|
||||
import io.ktor.client.call.*
|
||||
import io.ktor.client.plugins.*
|
||||
import kotlinx.coroutines.flow.first
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
|
@ -29,12 +31,29 @@ internal class DefaultProfileService(
|
|||
private suspend fun fetchMe(): ProfileService.Me {
|
||||
val credentials = credentialsStore.credentials()!!
|
||||
val userId = credentials.userId
|
||||
val result = httpClient.execute(profileRequest(userId))
|
||||
return ProfileService.Me(
|
||||
userId,
|
||||
result.displayName,
|
||||
result.avatarUrl?.convertMxUrToUrl(credentials.homeServer)?.let { AvatarUrl(it) },
|
||||
homeServerUrl = credentials.homeServer,
|
||||
return runCatching { httpClient.execute(profileRequest(userId)) }.fold(
|
||||
onSuccess = {
|
||||
ProfileService.Me(
|
||||
userId,
|
||||
it.displayName,
|
||||
it.avatarUrl?.convertMxUrToUrl(credentials.homeServer)?.let { AvatarUrl(it) },
|
||||
homeServerUrl = credentials.homeServer,
|
||||
)
|
||||
},
|
||||
onFailure = {
|
||||
when {
|
||||
it is ClientRequestException && it.response.status.value == 404 -> {
|
||||
ProfileService.Me(
|
||||
userId,
|
||||
displayName = null,
|
||||
avatarUrl = null,
|
||||
homeServerUrl = credentials.homeServer,
|
||||
)
|
||||
}
|
||||
|
||||
else -> throw it
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue