Last active
April 3, 2018 09:17
-
-
Save liminal/c6035ab54c61c642ceb019dc16e0fcec to your computer and use it in GitHub Desktop.
[Reasonable app error-handling for RxJava2] #android #rx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
RxJavaPlugins.setErrorHandler( | |
{ err -> | |
var e = err | |
if (e is UndeliverableException) { | |
e = e.cause | |
} | |
when (e) { | |
is IOException, is SocketException -> return@setErrorHandler // fine, irrelevant network problem or API that throws on cancellation | |
is InterruptedException -> return@setErrorHandler // fine, some blocking code was interrupted by a dispose call | |
is NullPointerException, is IllegalArgumentException -> { | |
// that's likely a bug in the application | |
Thread.currentThread().uncaughtExceptionHandler.uncaughtException(Thread.currentThread(), e) | |
return@setErrorHandler | |
} | |
is IllegalStateException -> { | |
// that's a bug in RxJava or in a custom operator | |
Thread.currentThread().uncaughtExceptionHandler.uncaughtException(Thread.currentThread(), e) | |
return@setErrorHandler | |
} | |
else -> Timber.w(e, "Undeliverable exception received, not sure what to do") | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment