Comments: properly handle errors

Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>
This commit is contained in:
Harsh Shandilya
2021-04-13 02:33:44 +05:30
parent cbdb6c0934
commit c409b72beb
@@ -58,7 +58,13 @@ fun CommentsPage(
) {
var postDetails: NetworkState by remember { mutableStateOf(NetworkState.Loading) }
LaunchedEffect(postId) { postDetails = NetworkState.Success(getDetails(postId)) }
LaunchedEffect(postId) {
postDetails = try {
NetworkState.Success(getDetails(postId))
} catch (e: Throwable) {
NetworkState.Error(e.message ?: "Failed to load posts")
}
}
when (postDetails) {
is NetworkState.Success<*> -> {