Avoid crashing when clearing cookies for invalid source URLs

e.g. Komga sources with no URLs set
This commit is contained in:
arkon 2022-12-05 22:18:19 -05:00
parent 09cebf20f3
commit b6d6de6b9f

View File

@ -115,11 +115,16 @@ class ExtensionDetailsScreenModel(
val urls = extension.sources val urls = extension.sources
.filterIsInstance<HttpSource>() .filterIsInstance<HttpSource>()
.map { it.baseUrl } .mapNotNull { it.baseUrl.takeUnless { url -> url.isEmpty() } }
.distinct() .distinct()
val cleared = urls.sumOf { val cleared = urls.sumOf {
try {
network.cookieManager.remove(it.toHttpUrl()) network.cookieManager.remove(it.toHttpUrl())
} catch (e: Exception) {
logcat(LogPriority.ERROR, e) { "Failed to clear cookies for $it" }
0
}
} }
logcat { "Cleared $cleared cookies for: ${urls.joinToString()}" } logcat { "Cleared $cleared cookies for: ${urls.joinToString()}" }