Hi folks, I'm trying to migrate from my own Redux ...
# orbit-mvi
a
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,
Copy code
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
In your container host you can install the exception handler e.g.
Copy code
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
Thanks @Mikolaj Leszczynski.👍🏻
o
personally I would think about container's exceptionHandler as a last guardian: not to crash the app, log all the exceptions, etc. The exception handling should be better done at the call site via simple try-catch, as orbit uses SupervisorJob that allows try-catching call site exceptions inside intent{}