Baking-App-Kotlin: Retrofit Coroutine Exception Handling
Does the current view state handle retrofit exception? E.g: 4xx or 5xx Retrofit error response/body
CMIIW, I cannot find try-catch
blocks in your ViewModel, Processor, Remote & Repository to handle that
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 16 (7 by maintainers)
Agreed!
Previously we’re using flow builder and after a while searching on the internet, then we’re using the extension to reduce boilerplate, as stated in Kotlin Flow code it has same purpose:
Or using method references approach:
Closing this issue, because it already answered our usecase. Thanks a lot & much appreciate it once again @Ezike
@mochadwi Yes it does handle exceptions. When using flow, you handle exceptions by using the catch operator which will catch exceptions that occur upstream. The
catch
operator doesn’t handle exceptions for any operations added after it. For example, in the RecipeActionProcessor, you’ll find this code:Check out this article too for more context. https://medium.com/@elizarov/exceptions-in-kotlin-flows-b59643c940fb