Error with Flowable's onErrorResumeNext, networkOnMainThread : <p>I have the following rxJava chain:</p>

<pre><code> override fun combineLocationToPlace(req: Flowable&lt;Place&gt;): Flowable&lt;Place&gt; {
        var combinedFlowable = Flowable
                .combineLatest(
                        req,
                        getLastLocation().lastOrError().toFlowable(),
                        BiFunction&lt;Place, Location, Place&gt; { t1, location -&gt;
                            Timber.w("FIRSTINIT - Retrieved location $location")
                            var placeLocation = Location(t1.placeName)
                            placeLocation.latitude = t1.latitude
                            placeLocation.longitude = t1.longitude
                            t1.distance = location.distanceTo(placeLocation)
                            t1
                        })


        return combinedFlowable
                .onErrorResumeNext { t: Throwable -&gt;
                    Timber.w(t, "FIRSTINIT - Could not retrieve location for place (${t.message}) returning original request")
                    req
                }
                .doOnError {
                    Timber.w("FIRSTINIT - did detect the error here...")
                }

        return combinedFlowable
    }
</code></pre>

<p>In short, I am retrieving some data from the local database (a place) and I want to combine it with the latest location from the GPS:</p>

<pre><code> override fun getLastLocation(requestIfEmpty: Boolean): Observable&lt;Location&gt; {
        var lastLocation = locationProvider.lastKnownLocation
                .doOnNext {
                    Timber.w("Got location $it from last one")
                }
                .doOnComplete {
                    Timber.w("did i get a location?")
                }

        if (requestIfEmpty) {
            Timber.w("Switching to request of location")
            lastLocation = lastLocation.switchIfEmpty(requestLocation())
        }

        return lastLocation.doOnNext {
            Timber.w("Got something!")
            location = it
        }


    }
</code></pre>

<p>But I want to account for the scneario where the user does not have a last location, and thus the line:</p>

<pre><code>return combinedFlowable
                    .onErrorResumeNext { t: Throwable -&gt;
                        Timber.w(t, "FIRSTINIT - Could not retrieve location for place (${t.message}) returning original request")
                        req
                    }
                    .doOnError {
                        Timber.w("FIRSTINIT - did detect the error here...")
                    }
</code></pre>

<p>Which is trying to catch any error and retry just with the original request without combining it with anything. I am calling this code like this:</p>

<pre><code>fun getPlace(placeId: String) {
        locationManager.combineLocationToPlace(placesRepository.getPlace(placeId))
                .onErrorResumeNext { t: Throwable -&gt;
                    Timber.e(t, "Error resuming next! ")
                    placesRepository.getPlace(placeId)
                }.subscribeOn(schedulerProvider.io()).observeOn(schedulerProvider.ui())
                .subscribeBy(
                        onNext = {
                            place.value = Result.success(it)
                        },
                        onError = {
                            Timber.e("ERROR! $it")
                            place.value = Result.failure(it)
                        }
                )
                .addTo(disposables)

    }
</code></pre>

<p>However, when there is no location a <code>NoSuchElementException</code> is thrown, my flowable switches to the original request, and then upon executing it I get a <code>NetworkOnMainThread</code> exception. Shouldn't this request be executed on the <code>scheduler.io()</code> that I put in there (since I put the code before that)?</p>

<p>In case you are wondering, <code>schedulerProvider.io()</code> translates to:</p>

<pre><code>Schedulers.io()
</code></pre>

<p>GetPlace:</p>

<pre><code>  /**
     * Retrieves a single place from database
     */
      override fun getPlace(id: String): Flowable&lt;Place&gt; {
        return Flowable.merge(placesDao.getPlace(id),
                refreshPlace(id).toFlowable())
    }

    /**
     * Triggers a refreshPlace update on the db, useful when changing stuff associated with the place
     * itself indirectly (e.g. an experience)
     */
    private fun refreshPlace(id: String): Single&lt;Place&gt; {
        return from(placesApi.getPlace(id))
                .doOnSuccess {
                    placesDao.savePlace(it)
                }
    }
</code></pre>
