diff --git a/app/src/main/java/org/schabi/newpipe/paging/CommentRepliesSource.kt b/app/src/main/java/org/schabi/newpipe/paging/CommentRepliesSource.kt index 37eddceb175..21e027835c0 100644 --- a/app/src/main/java/org/schabi/newpipe/paging/CommentRepliesSource.kt +++ b/app/src/main/java/org/schabi/newpipe/paging/CommentRepliesSource.kt @@ -15,12 +15,20 @@ class CommentRepliesSource( private val service = NewPipe.getService(commentInfo.serviceId) override suspend fun load(params: LoadParams): LoadResult { - // params.key is null the first time load() is called, and we need to return the first page - val repliesPage = params.key ?: commentInfo.replies - val info = withContext(Dispatchers.IO) { - CommentsInfo.getMoreItems(service, commentInfo.url, repliesPage) + return try { + // params.key is null the first time load() is called, and we need to return the first page + val repliesPage = params.key ?: commentInfo.replies + + val info = withContext(Dispatchers.IO) { + CommentsInfo.getMoreItems(service, commentInfo.url, repliesPage) + } + + LoadResult.Page(info.items, null, info.nextPage) + } catch (e: Exception) { + // Catches UnknownHostException (offline) or any extraction errors + // and tells Paging3 to show the error state in the UI. + LoadResult.Error(e) } - return LoadResult.Page(info.items, null, info.nextPage) } override fun getRefreshKey(state: PagingState) = null