We should also briefly mention how to handle notifications when we are unable to read remote financial stock data.
As we saw in the section dedicated to error handling, a good approach would be to show a Toast notification. So, to inform the user, we will just reuse the code we created before:
.doOnError(error -> {
Toast.makeText(this, "We couldn't reach internet - falling back to local data",
Toast.LENGTH_SHORT)
.show();
})
In a larger context of the flow, this will look as shown:
.flatMap(
i -> Observable.<YahooStockResult>error(new RuntimeException("Crash"))
)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.doOnError(error -> {
Toast.makeText(this, "We couldn't reach internet - falling back to
local data",
Toast.LENGTH_SHORT)
.show();
})
.observeOn(Schedulers.io())
Just to get a feeling where it should be put.