title: Architecture Components Retrofit and RxJava 2 error handling
body: <p>I am currently trying to implement the new ViewModels in the architecture components with an API request from retrofit and Okhttp, everything is working but I can't figure out how to pass an error response from retrofit to <code>LiveDataReactiveStreams.fromPublisher</code> and then upstream to the observer in the fragment. This is what I have so far:</p>
  
  <pre><code>public class ShowListViewModel extends AndroidViewModel {
  
  private final ClientAdapter clientAdapter;
  
  private LiveData&lt;List&lt;Show&gt;&gt; shows;
  
  public ShowListViewModel(Application application) {
      super(application);
      clientAdapter = new ClientAdapter(getApplication().getApplicationContext());
  
      loadShows();
  }
  
  public LiveData&lt;List&lt;Show&gt;&gt; getShows() {
      if (shows == null) {
          shows = new MutableLiveData&lt;&gt;();
      }
  
      return shows;
  }
  
  void loadShows() {
      shows = LiveDataReactiveStreams.fromPublisher(Observable.fromIterable(ShowsUtil.loadsIds())
              .subscribeOn(Schedulers.io())
              .flatMap(clientAdapter::getShowWithNextEpisode)
              .observeOn(Schedulers.computation())
              .toSortedList(new ShowsUtil.ShowComparator())
              .observeOn(AndroidSchedulers.mainThread())
              .toFlowable());
  }
  </code></pre>
  
  <p>And in the fragment I setup the viewModel with the following in OnCreate:</p>
  
  <pre><code>ShowListViewModel model = ViewModelProviders.of(this).get(ShowListViewModel.class);
      model.getShows().observe(this, shows -&gt; {
          if (shows == null || shows.isEmpty()) {
              //This is where we may have empty list etc....
          } else {
              //process results from shows list here
          }
  
      });
  </code></pre>
  
  <p>Everything works as expected but currently if we are offline then retrofit is throwing a runtimeException and crashing. I think the problem lies here:</p>
  
  <pre><code>LiveDataReactiveStreams.fromPublisher(Observable.fromIterable(ShowsUtil.loadsIds())
              .subscribeOn(Schedulers.io())
              .flatMap(clientAdapter::getShowWithNextEpisode)
              .observeOn(Schedulers.computation())
              .toSortedList(new ShowsUtil.ShowComparator())
              .observeOn(AndroidSchedulers.mainThread())
              .toFlowable());
  }
  </code></pre>
  
  <p>Normally we would use rxjava2 subscribe and catch the error from retrofit there, but when using <a href="https://developer.android.com/reference/android/arch/lifecycle/LiveDataReactiveStreams.html" rel="nofollow noreferrer">LiveDataReactiveStreams.fromPublisher</a> it subscribes to the flowable for us. So how do we pass this error into here:</p>
  
  <p><code>model.getShows().observe(this, shows -&gt; { //process error in fragment});</code></p>