Skip to content

Commit dd917ca

Browse files
authored
Merge pull request #13418 from Ecomont/fix/offline-comments-crash
Fix crash when loading offline comments in CommentRepliesSource
2 parents ae03b4f + 064458c commit dd917ca

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

app/src/main/java/org/schabi/newpipe/paging/CommentRepliesSource.kt

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,20 @@ class CommentRepliesSource(
1515
private val service = NewPipe.getService(commentInfo.serviceId)
1616

1717
override suspend fun load(params: LoadParams<Page>): LoadResult<Page, CommentsInfoItem> {
18-
// params.key is null the first time load() is called, and we need to return the first page
19-
val repliesPage = params.key ?: commentInfo.replies
20-
val info = withContext(Dispatchers.IO) {
21-
CommentsInfo.getMoreItems(service, commentInfo.url, repliesPage)
18+
return try {
19+
// params.key is null the first time load() is called, and we need to return the first page
20+
val repliesPage = params.key ?: commentInfo.replies
21+
22+
val info = withContext(Dispatchers.IO) {
23+
CommentsInfo.getMoreItems(service, commentInfo.url, repliesPage)
24+
}
25+
26+
LoadResult.Page(info.items, null, info.nextPage)
27+
} catch (e: Exception) {
28+
// Catches UnknownHostException (offline) or any extraction errors
29+
// and tells Paging3 to show the error state in the UI.
30+
LoadResult.Error(e)
2231
}
23-
return LoadResult.Page(info.items, null, info.nextPage)
2432
}
2533

2634
override fun getRefreshKey(state: PagingState<Page, CommentsInfoItem>) = null

0 commit comments

Comments
 (0)