improve error reporting

This commit is contained in:
Phillip Thelen 2017-05-25 15:16:00 +02:00
parent 8949f6a625
commit 2a193a60ad
2 changed files with 23 additions and 5 deletions

View file

@ -132,6 +132,9 @@ public abstract class HabiticaBaseApplication extends MultiDexApplication {
}
}
Fresco.initialize(this);
RxErrorHandler.init(crashlyticsProxy);
checkIfNewVersion();
}

View file

@ -2,21 +2,36 @@ package com.habitrpg.android.habitica.helpers;
import android.util.Log;
import rx.android.BuildConfig;
import com.habitrpg.android.habitica.BuildConfig;
import com.habitrpg.android.habitica.proxy.CrashlyticsProxy;
import rx.functions.Action1;
public class RxErrorHandler {
static private RxErrorHandler instance;
private CrashlyticsProxy crashlyticsProxy;
public static void init(CrashlyticsProxy crashlyticsProxy) {
instance = new RxErrorHandler();
instance.crashlyticsProxy = crashlyticsProxy;
}
public static Action1<Throwable> handleEmptyError() {
//Can't be turned into a lambda, because it then doesn't work for some reason.
return new Action1<Throwable>() {
@Override
public void call(Throwable throwable) {
throwable.printStackTrace();
if (BuildConfig.DEBUG) {
Log.e("ObservableError", Log.getStackTraceString(throwable));
}
RxErrorHandler.reportError(throwable);
}
};
}
private static void reportError(Throwable throwable) {
if (BuildConfig.DEBUG) {
Log.e("ObservableError", Log.getStackTraceString(throwable));
} else {
instance.crashlyticsProxy.logException(throwable);
}
}
}