I’m refactoring a sample project to use Paging3 lib, before using it I handled errors (domain and data and presentation layers) using
- A sealed class UI layer
- Flow extension (
asResult
that manages error and retry)
While Paging3 lib is handling State
internally I removed the sealed class and the flow extension and I used (only) the Response
class from retrofit2 as bellow :
ApiService
suspend fun getPosts(@Query("page") page: Int): Response<Page<PostDTO>>
Repo
@Singleton
internal class DefaultPostRepository @Inject constructor(
private val postService: PostService, private val postMapper: PostMapper,
) : PostsRepository {
override fun getPosts(postId: Int): Flow<List<PostModel>> = flow {
postService.getPosts(postId).let {
if (it.isSuccessful) {
val fromListDto = postMapper.fromListDto(postService.getPosts(postId).body()!!.data)
emit(fromListDto)
} else {
emit(emptyList())
}
}
}
is it any better way to make error management better or still need to keep the selead class and the Flow extention?