Skip to content

Commit 4574f98

Browse files
committed
Improve UrlCleaner handler if modules fails
Show log message error and skip to next module.
1 parent 4e8080d commit 4574f98

2 files changed

Lines changed: 14 additions & 7 deletions

File tree

app/src/main/java/com/wstxda/clippy/cleaner/tools/UrlCleaner.kt

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,27 @@ import com.wstxda.clippy.cleaner.providers.UrlSchemeProvider
88
import kotlinx.coroutines.Dispatchers
99
import kotlinx.coroutines.withContext
1010
import androidx.core.net.toUri
11+
import android.util.Log
12+
import com.wstxda.clippy.utils.Constants
1113

1214
object UrlCleaner {
13-
private val applyCleaningModules =
14-
listOf<suspend (String) -> String>(
15-
{ url -> RedirectionHandler.resolveRedirectionParams(url) },
16-
{ url -> TrackerRemover.removeTrackersParams(url) },
17-
{ url -> ShortenerRemover.removeShortenerParams(url) },
18-
{ url -> BuiltinRulesResolver.applyBuiltinRules(url) })
15+
private val applyCleaningModules = listOf<suspend (String) -> String>(
16+
{ url -> RedirectionHandler.resolveRedirectionParams(url) },
17+
{ url -> TrackerRemover.removeTrackersParams(url) },
18+
{ url -> ShortenerRemover.removeShortenerParams(url) },
19+
{ url -> BuiltinRulesResolver.applyBuiltinRules(url) })
1920

2021
suspend fun startUrlCleanerModules(url: String): String = withContext(Dispatchers.IO) {
2122
val uri = url.toUri()
2223
val scheme = uri.scheme
2324
if (scheme != null && UrlSchemeProvider.needsCleaning(scheme)) {
2425
applyCleaningModules.fold(url) { currentUrl, cleaner ->
25-
cleaner(currentUrl)
26+
try {
27+
cleaner(currentUrl)
28+
} catch (e: Exception) {
29+
Log.e(Constants.URL_CLEANER, "Error applying cleaner module to URL: ${e.message}", e)
30+
currentUrl
31+
}
2632
}
2733
} else {
2834
url

app/src/main/java/com/wstxda/clippy/utils/Constants.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ object Constants {
1010
const val REDIRECTION_HANDLER = "RedirectionHandler"
1111
const val LINK_PROCESSOR = "LinkProcessor"
1212
const val URL_VALIDATOR = "UrlValidator"
13+
const val URL_CLEANER = "UrlCleaner"
1314
}

0 commit comments

Comments
 (0)