diff options
4 files changed, 36 insertions, 11 deletions
diff --git a/app/src/main/java/de/danoeh/antennapod/discovery/ItunesTopListLoader.java b/app/src/main/java/de/danoeh/antennapod/discovery/ItunesTopListLoader.java index bc9133258..79ccd9532 100644 --- a/app/src/main/java/de/danoeh/antennapod/discovery/ItunesTopListLoader.java +++ b/app/src/main/java/de/danoeh/antennapod/discovery/ItunesTopListLoader.java @@ -33,16 +33,12 @@ public class ItunesTopListLoader { OkHttpClient client = AntennapodHttpClient.getHttpClient(); String feedString; try { - try { - feedString = getTopListFeed(client, lang, limit); - } catch (IOException e) { - feedString = getTopListFeed(client, "us", limit); - } - List<PodcastSearchResult> podcasts = parseFeed(feedString); - emitter.onSuccess(podcasts); - } catch (IOException | JSONException e) { - emitter.onError(e); + feedString = getTopListFeed(client, lang, limit); + } catch (IOException e) { + feedString = getTopListFeed(client, "us", limit); } + List<PodcastSearchResult> podcasts = parseFeed(feedString); + emitter.onSuccess(podcasts); }) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()); diff --git a/core/src/free/java/de/danoeh/antennapod/core/ClientConfig.java b/core/src/free/java/de/danoeh/antennapod/core/ClientConfig.java index c17376639..9ed5f0392 100644 --- a/core/src/free/java/de/danoeh/antennapod/core/ClientConfig.java +++ b/core/src/free/java/de/danoeh/antennapod/core/ClientConfig.java @@ -34,7 +34,7 @@ public class ClientConfig { private static boolean initialized = false; public static synchronized void initialize(Context context) { - if(initialized) { + if (initialized) { return; } PodDBAdapter.init(context); @@ -42,6 +42,7 @@ public class ClientConfig { PlaybackPreferences.init(context); NetworkUtils.init(context); SleepTimerPreferences.init(context); + RxJavaErrorHandlerSetup.setupRxJavaErrorHandler(); initialized = true; } diff --git a/core/src/main/java/de/danoeh/antennapod/core/util/exception/RxJavaErrorHandlerSetup.java b/core/src/main/java/de/danoeh/antennapod/core/util/exception/RxJavaErrorHandlerSetup.java new file mode 100644 index 000000000..431760708 --- /dev/null +++ b/core/src/main/java/de/danoeh/antennapod/core/util/exception/RxJavaErrorHandlerSetup.java @@ -0,0 +1,26 @@ +package de.danoeh.antennapod.core.util.exception; + +import android.util.Log; +import io.reactivex.exceptions.UndeliverableException; +import io.reactivex.plugins.RxJavaPlugins; + +public class RxJavaErrorHandlerSetup { + + private RxJavaErrorHandlerSetup() { + + } + + public static void setupRxJavaErrorHandler() { + RxJavaPlugins.setErrorHandler(e -> { + if (e instanceof UndeliverableException) { + e = e.getCause(); + } + if (e instanceof InterruptedException) { + // fine, some blocking code was interrupted by a dispose call + Log.d("RxJavaErrorHandler", "Ignored exception: " + Log.getStackTraceString(e)); + return; + } + Thread.currentThread().getUncaughtExceptionHandler().uncaughtException(Thread.currentThread(), e); + }); + } +} diff --git a/core/src/play/java/de/danoeh/antennapod/core/ClientConfig.java b/core/src/play/java/de/danoeh/antennapod/core/ClientConfig.java index 862fe23f5..244fb0254 100644 --- a/core/src/play/java/de/danoeh/antennapod/core/ClientConfig.java +++ b/core/src/play/java/de/danoeh/antennapod/core/ClientConfig.java @@ -8,6 +8,7 @@ import de.danoeh.antennapod.core.preferences.SleepTimerPreferences; import de.danoeh.antennapod.core.preferences.UserPreferences; import de.danoeh.antennapod.core.storage.PodDBAdapter; import de.danoeh.antennapod.core.util.NetworkUtils; +import de.danoeh.antennapod.core.util.exception.RxJavaErrorHandlerSetup; /** * Stores callbacks for core classes like Services, DB classes etc. and other configuration variables. @@ -36,7 +37,7 @@ public class ClientConfig { private static boolean initialized = false; public static synchronized void initialize(Context context) { - if(initialized) { + if (initialized) { return; } PodDBAdapter.init(context); @@ -45,6 +46,7 @@ public class ClientConfig { NetworkUtils.init(context); CastManager.init(context); SleepTimerPreferences.init(context); + RxJavaErrorHandlerSetup.setupRxJavaErrorHandler(); initialized = true; } |