Reputation: 47
My problem is rxJava error The exception was not handled due to missing onError handler in the subscribe() method call. what is fix this?
compositeDisposable.add(backendApi.createEphemeralKey(params)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe { response ->
try {
val rawKey = response.string()
keyUpdateListener.onKeyUpdate(rawKey)`
} catch (e: IOException) {
keyUpdateListener
.onKeyUpdateFailure(0, e.message ?: "")
}
})
Upvotes: 0
Views: 1488
Reputation: 911
As the error suggests,
compositeDisposable.add(backendApi.createEphemeralKey(params)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe ({ response ->
val rawKey = response.string()
keyUpdateListener.onKeyUpdate(rawKey)
}, // onError goes here as 2nd lambda parameter
{e ->
keyUpdateListener.onKeyUpdateFailure(0, e.message ?: "")
})
)
This is basic error handling, please refer to docs Error Handling Operators
WARNING: Your question is too basic and is already answered, you will receive downvotes and duplicate flags.
Edit: I think the signature difference is because the Rx version you are using. anyway, the above should work with RxJava2 with your module targeting Java 8 at least to support lambdas.
Upvotes: 2