https://kotlinlang.org logo
Title
a

Abhijeet Kumar

03/29/2023, 6:41 AM
Hi folks, I'm trying to migrate from my own Redux like architecture to Orbit. I wanted to know how exception handling can be done via orbit. For ex. If my usecase which is making a network call and the endpoint is unreachable, the usecase will throw SockectTimeOutException. This particular exception will be handled inside an instance of CoroutineExceptionHandler which will decide the next state based on the type of exception. Ex,
private val exceptionHandler = CoroutineExceptionHandler { coroutineContext, throwable ->
    _homeAssetDetailFragmentState.update {
        homeAssetDetailErrorReducer.reduce(throwable, it)
    }
}
Do we've something similar for Orbit? I looked into the docs, there was something OrbitExceptionHandler, but couldn't find working example for this. Please help me out
m

Mikolaj Leszczynski

03/29/2023, 7:27 AM
In your container host you can install the exception handler e.g.
val exceptionHandler = CoroutineExceptionHandler { _, throwable -> 
                intent { 
                    reduce { ... }
                }
            }
override val container = container<Int, Nothing>(
                initialState = initState,
                settings = Container.Settings(
                    exceptionHandler = exceptionHandler,
                )
            )
I personally think that the best practice is to handle errors at the call site though.
a

Abhijeet Kumar

03/29/2023, 3:54 PM
Thanks @Mikolaj Leszczynski.👍🏻