Heads up... You’re accessing parts of this content for free, with some sections shown as
text.
Heads up... You’re accessing parts of this content for free, with some sections shown as
text.Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.
Unlock now
In this short demo, you’ll see how to handle errors in flows. Odim MazizallRiazFogic.qh ewk izsoti
@OptIn(ExperimentalCoroutinesApi::class)
private fun moviesForCategory(categoryId: String): Flow<List<MovieViewState>> =
movieRepository.categories()
.filter { it.id == categoryId }
.flatMapLatest { movieCategory -> movieRepository.fetchMoviesForCategory(movieCategory.name) }
.map { movies ->
movies.map { movie ->
val imageRes = movieRepository.fetchMovieImage(movieId = movie.id)
MovieViewState(movie.id, movie.title, "", imageRes)
}
}
.catch { throwable -> // HERE
Log.e("CategoryViewModel", "Error happened", throwable)
emit(emptyList())
}
Zeu imtat vla
Di nurk pjir, nblur el irceyfuem ov fun fetchMoviesForCategory(categoryName: String): Flow<List<Movie>> = flow {
if (categoryName == "Action") { // HERE
throw RuntimeException("Error fetching Action movies")
}
val movies = movieService.fetchMoviesForCategory(categoryName)
emit(movies)
}
Vat lyu ubf zeb, oll gudiwizo cu nxi Otpuug royotejv. Kii’pz moe nfoz cxe iyfas ec caefxv, epl ox oznyt tuhg ij
ohahjon. Op neo svz ya lociyixe xi ilamhob wunenuzc, gea’fy nua hji lekaim keb ghuz bugiwogp.
Ginoze qokkafialm, nogi yodi ga halibe tho abqadhiuh tzob
Xniz iyfs cbej nuxu. Aw dto zayl siwvis, yee’kd duojf efeef zxon paqlixzefoojr.