From f69c569406a6c67c92f5ec2f5fd544dc72a6a8ad Mon Sep 17 00:00:00 2001 From: Harsh Shandilya Date: Sun, 18 Sep 2022 22:15:02 +0530 Subject: [PATCH] refactor(common): ensure comments page can handle errors --- .../kotlin/dev/msfjarvis/claw/common/comments/Comments.kt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/common/src/main/kotlin/dev/msfjarvis/claw/common/comments/Comments.kt b/common/src/main/kotlin/dev/msfjarvis/claw/common/comments/Comments.kt index dd733feb..2f2751e6 100644 --- a/common/src/main/kotlin/dev/msfjarvis/claw/common/comments/Comments.kt +++ b/common/src/main/kotlin/dev/msfjarvis/claw/common/comments/Comments.kt @@ -73,7 +73,11 @@ fun CommentsPage( ) { val postDetails by produceState(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) {