Added an error handler to the RxBus instance subscription call

This commit is contained in:
Nelson R. Perez 2019-01-31 15:27:00 -05:00
parent c7138c5e22
commit 65250c57f5

View file

@ -147,7 +147,11 @@ abstract class ConnectedActivity : AppCompatActivity(), ServiceConnection {
mDisposable = RxBus.getBusInstance() mDisposable = RxBus.getBusInstance()
.asFlowable() .asFlowable()
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe { handleIncomingMessage(it) } .subscribe({
this.handleIncomingMessage(it)
}, {
this.handleError(it)
})
} }
/** /**
@ -161,6 +165,19 @@ abstract class ConnectedActivity : AppCompatActivity(), ServiceConnection {
mCurrentAccount = UserAccount(userId) mCurrentAccount = UserAccount(userId)
} }
/**
* Error consumer used to handle potential errors caused by the NetworkService while processing
* incoming data.
*/
private fun handleError(throwable: Throwable){
Log.e(TAG, "Error while processing received message. Msg: " + throwable.message)
val stack = throwable.stackTrace
for (e in stack) {
Log.e(TAG, String.format("%s#%s:%d", e.className, e.methodName, e.lineNumber))
}
Crashlytics.log(Log.ERROR, TAG, "ConnectedActivity reporting error. Msg: ${throwable.message}")
}
private fun handleIncomingMessage(message: Any?) { private fun handleIncomingMessage(message: Any?) {
if (message is JsonRpcResponse<*>) { if (message is JsonRpcResponse<*>) {