From fbf949974bdd79c177431e83fbbe7cd87af76b89 Mon Sep 17 00:00:00 2001 From: Sasikanth Miriyampalli Date: Sat, 17 Feb 2024 20:31:12 +0530 Subject: [PATCH] Catch HTML parsing errors when fetching feed --- .../rss/reader/core/network/fetcher/FeedFetcher.kt | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/core/network/src/commonMain/kotlin/dev/sasikanth/rss/reader/core/network/fetcher/FeedFetcher.kt b/core/network/src/commonMain/kotlin/dev/sasikanth/rss/reader/core/network/fetcher/FeedFetcher.kt index b88b8449e..df591a01a 100644 --- a/core/network/src/commonMain/kotlin/dev/sasikanth/rss/reader/core/network/fetcher/FeedFetcher.kt +++ b/core/network/src/commonMain/kotlin/dev/sasikanth/rss/reader/core/network/fetcher/FeedFetcher.kt @@ -145,7 +145,13 @@ class FeedFetcher(private val httpClient: HttpClient, private val feedParser: Fe } private fun fetchFeedLinkFromHtmlIfExists(htmlContent: String, originalUrl: String): String? { - val document = Ksoup.parse(htmlContent) + val document = + try { + Ksoup.parse(htmlContent) + } catch (t: Throwable) { + return null + } + val linkElement = document.getElementsByTag(TAG_LINK).firstOrNull { val linkType = it.attr(ATTR_TYPE)