title: Handling Network Error in Rxjava 2 - Retrofit 2
body: <p>How can we handle different network errors in Rxjava2 ?</p>
  
  <p>We used to check the instance of the throwable if it's of IOException or HttpException back with Rxjava 1 ,however, in RxJava 2 the throwable error is of type <strong>GaiException</strong>.</p>
  
  <p>code snippet</p>
  
  <pre><code>RestAPI restAPI = RetrofitHelper.createRetrofitWithGson().create(RestAPI.class);
  Observable&lt;BaseResponseTourPhoto&gt; observable = restAPI.fetchData("Bearer " + getAccessToken(), "2", "" + page)
          .subscribeOn(Schedulers.io())
          .observeOn(AndroidSchedulers.mainThread());
  
  Disposable subscription = observable.subscribe(BaseResponse-&gt; {
      onLoadingFinish(isPageLoading, isRefreshing);
      onLoadingSuccess(isPageLoading, BaseResponse);
      writeToRealm(BaseResponse.getData());
  }, error -&gt; {
      onLoadingFinish(isPageLoading, isRefreshing);
      onLoadingFailed(error);
  });
  
  mCompositeDisposable = new CompositeDisposable();
  mCompositeDisposable.add(subscription);
  unsubscribeOnDestroy(mCompositeDisposable);
  </code></pre>
  
  <p>reference: <a href="https://github.com/square/retrofit/issues/690" rel="noreferrer">https://github.com/square/retrofit/issues/690</a>
  <a href="https://android.googlesource.com/platform/libcore/+/5d930ca/luni/src/main/java/android/system/GaiException.java" rel="noreferrer">https://android.googlesource.com/platform/libcore/+/5d930ca/luni/src/main/java/android/system/GaiException.java</a></p>