1
0
mirror of https://github.com/wulkanowy/wulkanowy.git synced 2025-01-18 20:56:46 -06:00

Don't log common errors to crashlytics (#775)

This commit is contained in:
Mikołaj Pich 2020-04-18 23:07:20 +02:00 committed by GitHub
parent b19084cb57
commit 4bd0459155
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 25 additions and 13 deletions

View File

@ -1,7 +1,6 @@
package io.github.wulkanowy.services.sync
import android.content.Context
import android.os.Build.VERSION_CODES.LOLLIPOP
import androidx.core.app.NotificationCompat
import androidx.core.app.NotificationCompat.BigTextStyle
import androidx.core.app.NotificationCompat.PRIORITY_DEFAULT
@ -17,9 +16,9 @@ import io.github.wulkanowy.data.repositories.preferences.PreferencesRepository
import io.github.wulkanowy.data.repositories.semester.SemesterRepository
import io.github.wulkanowy.data.repositories.student.StudentRepository
import io.github.wulkanowy.sdk.exception.FeatureDisabledException
import io.github.wulkanowy.sdk.exception.FeatureNotAvailableException
import io.github.wulkanowy.services.sync.channels.DebugChannel
import io.github.wulkanowy.services.sync.works.Work
import io.github.wulkanowy.utils.AppInfo
import io.github.wulkanowy.utils.getCompatColor
import io.reactivex.Completable
import io.reactivex.Single
@ -33,8 +32,7 @@ class SyncWorker @AssistedInject constructor(
private val semesterRepository: SemesterRepository,
private val works: Set<@JvmSuppressWildcards Work>,
private val preferencesRepository: PreferencesRepository,
private val notificationManager: NotificationManagerCompat,
private val appInfo: AppInfo
private val notificationManager: NotificationManagerCompat
) : RxWorker(appContext, workerParameters) {
override fun createWork(): Single<Result> {
@ -47,6 +45,10 @@ class SyncWorker @AssistedInject constructor(
.flatMapCompletable { semester ->
Completable.mergeDelayError(works.map { work ->
work.create(student, semester)
.onErrorResumeNext {
if (it is FeatureDisabledException || it is FeatureNotAvailableException) Completable.complete()
else Completable.error(it)
}
.doOnSubscribe { Timber.i("${work::class.java.simpleName} is starting") }
.doOnError { Timber.i("${work::class.java.simpleName} result: An exception occurred") }
.doOnComplete { Timber.i("${work::class.java.simpleName} result: Success") }
@ -57,11 +59,11 @@ class SyncWorker @AssistedInject constructor(
.onErrorReturn {
Timber.e(it, "There was an error during synchronization")
when {
it is FeatureDisabledException -> Result.success()
inputData.getBoolean("one_time", false) -> {
Result.failure(Data.Builder()
.putString("error", it.toString())
.build())
.build()
)
}
else -> Result.retry()
}

View File

@ -133,7 +133,7 @@ class GradeStatisticsPresenter @Inject constructor(
showSubjects(true)
}
}, {
Timber.e("Loading grade stats subjects result: An exception occurred")
Timber.i("Loading grade stats subjects result: An exception occurred")
errorHandler.dispatch(it)
})
)
@ -179,7 +179,7 @@ class GradeStatisticsPresenter @Inject constructor(
}
analytics.logEvent("load_grade_statistics", "items" to it.size, "force_refresh" to forceRefresh)
}) {
Timber.e("Loading grade stats result: An exception occurred")
Timber.i("Loading grade stats result: An exception occurred")
errorHandler.dispatch(it)
})
}

View File

@ -70,7 +70,7 @@ class LoginRecoverPresenter @Inject constructor(
.subscribe({ (resetUrl, siteKey) ->
view?.loadReCaptcha(siteKey, resetUrl)
}) {
Timber.e("Obtain captcha site key result: An exception occurred")
Timber.i("Obtain captcha site key result: An exception occurred")
errorHandler.dispatch(it)
})
}
@ -120,7 +120,7 @@ class LoginRecoverPresenter @Inject constructor(
analytics.logEvent("account_recover", "register" to host, "symbol" to symbol, "success" to true)
}) {
Timber.e("Send recover request result: An exception occurred")
Timber.i("Send recover request result: An exception occurred")
errorHandler.dispatch(it)
analytics.logEvent("account_recover", "register" to host, "symbol" to symbol, "success" to false)
})

View File

@ -135,12 +135,12 @@ class SendMessagePresenter @Inject constructor(
if (selectedRecipientChips.isNotEmpty()) setSelectedRecipients(selectedRecipientChips)
showContent(true)
} else {
Timber.e("Loading recipients result: Can't find the reporting unit")
Timber.i("Loading recipients result: Can't find the reporting unit")
view?.showEmpty(true)
}
}
}, {
Timber.e("Loading recipients result: An exception occurred")
Timber.i("Loading recipients result: An exception occurred")
view?.showContent(true)
errorHandler.dispatch(it)
}))

View File

@ -7,6 +7,9 @@ import com.crashlytics.android.core.CrashlyticsCore
import fr.bipi.tressence.crash.CrashlyticsLogExceptionTree
import fr.bipi.tressence.crash.CrashlyticsLogTree
import io.fabric.sdk.android.Fabric
import io.github.wulkanowy.sdk.exception.FeatureDisabledException
import io.github.wulkanowy.sdk.exception.FeatureNotAvailableException
import java.net.UnknownHostException
fun initCrashlytics(context: Context, appInfo: AppInfo) {
Fabric.with(Fabric.Builder(context)
@ -21,6 +24,13 @@ fun initCrashlytics(context: Context, appInfo: AppInfo) {
.build())
}
class CrashlyticsTree : CrashlyticsLogTree(Log.VERBOSE)
class CrashlyticsTree : CrashlyticsLogTree(Log.VERBOSE) {
override fun log(priority: Int, tag: String?, message: String, t: Throwable?) {
if (t is FeatureDisabledException || t is FeatureNotAvailableException || t is UnknownHostException) return
super.log(priority, tag, message, t)
}
}
class CrashlyticsExceptionTree : CrashlyticsLogExceptionTree()