refactor(common): ensure comments page can handle errors

This commit is contained in:
Harsh Shandilya 2022-09-18 22:15:02 +05:30
parent e96ef78d1a
commit f69c569406
No known key found for this signature in database

View file

@ -73,7 +73,11 @@ fun CommentsPage(
) {
val postDetails by
produceState<NetworkState>(NetworkState.Loading) {
value = NetworkState.Success(getDetails(postId))
runCatching { getDetails(postId) }
.fold(
onSuccess = { details -> value = NetworkState.Success(details) },
onFailure = { value = NetworkState.Error("Failed to load comments") }
)
}
when (postDetails) {