Do not crash on undeliverable InterruptedException
This commit is contained in:
parent
f35286f1dc
commit
af8dc2c9b9
|
@ -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());
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue