From 5ed53ed0aacead137bac7dd652d645beb1c31f38 Mon Sep 17 00:00:00 2001 From: utsman Date: Thu, 20 Mar 2025 23:04:32 +0700 Subject: [PATCH] feat(router): Enhance layout fetching with error handling in RemoteRouter --sample-deploy - Adds error handling to `fetchLayoutAsFlow` in `RemoteRouter.kt` using the `catch` operator. - Updates `_layoutContent` state to `ResultLayout.failure` when an error occurs during layout fetching. --- .../kotlin/com/utsman/composeremote/router/RemoteRouter.kt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/compose-remote-layout-router/src/commonMain/kotlin/com/utsman/composeremote/router/RemoteRouter.kt b/compose-remote-layout-router/src/commonMain/kotlin/com/utsman/composeremote/router/RemoteRouter.kt index fe70921..cd754b9 100644 --- a/compose-remote-layout-router/src/commonMain/kotlin/com/utsman/composeremote/router/RemoteRouter.kt +++ b/compose-remote-layout-router/src/commonMain/kotlin/com/utsman/composeremote/router/RemoteRouter.kt @@ -4,6 +4,7 @@ import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.asStateFlow +import kotlinx.coroutines.flow.catch import kotlinx.coroutines.flow.collectLatest import kotlinx.coroutines.launch @@ -129,6 +130,9 @@ internal class ResultRemoteRouterImpl( scope.launch { fetcher.fetchLayoutAsFlow(url) + .catch { + _layoutContent.value = ResultLayout.failure(it) + } .collectLatest { result -> _layoutContent.value = result calculateIsRoot()