Don't log tryOrNull errors unnecessarily

This commit is contained in:
Moez Bhatti
2018-07-02 18:01:01 -04:00
parent 95b80ad408
commit 9cea675bd8
4 changed files with 10 additions and 7 deletions
@@ -72,10 +72,10 @@ class ExternalBlockingManagerImpl @Inject constructor(
// If either version of Should I Answer? is installed and SIA is enabled, build the
// intent to request a rating
if (prefs.sia.get()) {
intent = tryOrNull {
intent = tryOrNull(false) {
context.packageManager.getApplicationInfo("org.mistergroup.shouldianswerpersonal", 0).enabled
Intent("org.mistergroup.shouldianswerpersonal.PublicService").setPackage("org.mistergroup.shouldianswerpersonal")
} ?: tryOrNull {
} ?: tryOrNull(false) {
context.packageManager.getApplicationInfo("org.mistergroup.muzutozvednout", 0).enabled
Intent("org.mistergroup.muzutozvednout.PublicService").setPackage("org.mistergroup.muzutozvednout")
}
@@ -163,7 +163,7 @@ class SyncRepositoryImpl @Inject constructor(
}
// If we don't have a valid id, return null
val id = tryOrNull { ContentUris.parseId(uri) } ?: return null
val id = tryOrNull(false) { ContentUris.parseId(uri) } ?: return null
// Check if the message already exists, so we can reuse the id
val existingId = Realm.getDefaultInstance().use { realm ->
@@ -20,11 +20,14 @@ package com.moez.QKSMS.util
import timber.log.Timber
fun <T> tryOrNull(body: () -> T?): T? {
fun <T> tryOrNull(logOnError: Boolean = true, body: () -> T?): T? {
return try {
body()
} catch (e: Exception) {
Timber.w(e)
if (logOnError) {
Timber.w(e)
}
null
}
}