Add crash reporting via Crashlytics.

This commit is contained in:
Kevin Gorham 2020-02-21 18:49:45 -05:00
parent 8331e8ff06
commit 5803a9dd71
No known key found for this signature in database
GPG Key ID: CCA55602DF49FC38
2 changed files with 31 additions and 0 deletions

View File

@ -57,4 +57,9 @@ class AppModule {
@Singleton
@IntoSet
fun provideFeedbackMixpanel(): FeedbackCoordinator.FeedbackObserver = FeedbackMixpanel()
@Provides
@Singleton
@IntoSet
fun provideFeedbackCrashlytics(): FeedbackCoordinator.FeedbackObserver = FeedbackCrashlytics()
}

View File

@ -0,0 +1,26 @@
package cash.z.ecc.android.feedback
import com.crashlytics.android.Crashlytics
class FeedbackCrashlytics : FeedbackCoordinator.FeedbackObserver {
/**
* Report non-fatal crashes because fatal ones already get reported by default.
*/
override fun onAction(action: Feedback.Action) {
var exception: Throwable? = null
exception = when (action) {
is Feedback.Crash -> action.exception
is Feedback.NonFatal -> action.exception
is Report.Error.NonFatal.Reorg -> ReorgException(
action.errorHeight,
action.rewindHeight,
action.toString()
)
else -> null
}
exception?.let { Crashlytics.logException(it) }
}
private class ReorgException(errorHeight: Int, rewindHeight: Int, reorgMesssage: String) :
Throwable(reorgMesssage)
}