From 65250c57f5c24462bb894f3b9f595fc8afa91f40 Mon Sep 17 00:00:00 2001 From: "Nelson R. Perez" Date: Thu, 31 Jan 2019 15:27:00 -0500 Subject: [PATCH] Added an error handler to the RxBus instance subscription call --- .../activities/ConnectedActivity.kt | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/cy/agorise/bitsybitshareswallet/activities/ConnectedActivity.kt b/app/src/main/java/cy/agorise/bitsybitshareswallet/activities/ConnectedActivity.kt index b347a22..83a6fbc 100644 --- a/app/src/main/java/cy/agorise/bitsybitshareswallet/activities/ConnectedActivity.kt +++ b/app/src/main/java/cy/agorise/bitsybitshareswallet/activities/ConnectedActivity.kt @@ -147,7 +147,11 @@ abstract class ConnectedActivity : AppCompatActivity(), ServiceConnection { mDisposable = RxBus.getBusInstance() .asFlowable() .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) } + /** + * 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?) { if (message is JsonRpcResponse<*>) {