diff --git a/vector/src/main/java/im/vector/riotx/VectorApplication.kt b/vector/src/main/java/im/vector/riotx/VectorApplication.kt index 5ca888fc2e..875e6c417a 100644 --- a/vector/src/main/java/im/vector/riotx/VectorApplication.kt +++ b/vector/src/main/java/im/vector/riotx/VectorApplication.kt @@ -42,6 +42,7 @@ import im.vector.riotx.core.di.DaggerVectorComponent import im.vector.riotx.core.di.HasVectorInjector import im.vector.riotx.core.di.VectorComponent import im.vector.riotx.core.extensions.configureAndStart +import im.vector.riotx.core.rx.setupRxPlugin import im.vector.riotx.core.utils.initKnownEmojiHashSet import im.vector.riotx.features.configuration.VectorConfiguration import im.vector.riotx.features.lifecycle.VectorActivityLifecycleCallbacks @@ -55,8 +56,7 @@ import im.vector.riotx.features.version.VersionProvider import im.vector.riotx.push.fcm.FcmHelper import timber.log.Timber import java.text.SimpleDateFormat -import java.util.Date -import java.util.Locale +import java.util.* import javax.inject.Inject class VectorApplication : Application(), HasVectorInjector, MatrixConfiguration.Provider, androidx.work.Configuration.Provider { @@ -87,6 +87,7 @@ class VectorApplication : Application(), HasVectorInjector, MatrixConfiguration. vectorComponent = DaggerVectorComponent.factory().create(this) vectorComponent.inject(this) vectorUncaughtExceptionHandler.activate(this) + setupRxPlugin() if (BuildConfig.DEBUG) { Timber.plant(Timber.DebugTree()) diff --git a/vector/src/main/java/im/vector/riotx/core/rx/Rx.kt b/vector/src/main/java/im/vector/riotx/core/rx/Rx.kt new file mode 100644 index 0000000000..89de9030dc --- /dev/null +++ b/vector/src/main/java/im/vector/riotx/core/rx/Rx.kt @@ -0,0 +1,35 @@ +/* + * Copyright 2019 New Vector Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package im.vector.riotx.core.rx + +import im.vector.riotx.BuildConfig +import io.reactivex.plugins.RxJavaPlugins +import timber.log.Timber + +/** + * Make sure unhandled Rx error does not crash the app in production + */ +fun setupRxPlugin() { + RxJavaPlugins.setErrorHandler { throwable -> + Timber.e(throwable, "RxError") + + // Avoid crash in production + if (BuildConfig.DEBUG) { + throw throwable + } + } +}