Retrofit + RxJava FATAL MAIN on no network connection
<p>I have this weird error - when I log in (having network connection) and then I disable network then when I try to do <code>syncOne()</code> I get:</p>

<pre><code>    10-09 16:47:22.986 23444-23444/package.app.whatever E/asd-local-error: java.net.UnknownHostException: Unable to resolve host "cbm.aype.pl": No address associated with hostname/libcore.io.GaiException: getaddrinfo failed: EAI_NODATA (No address associated with hostname)/java.net.UnknownHostException: Unable to resolve host "myhost.com": No address associated with hostname
10-09 16:47:22.986 23444-23444/package.app.whatever E/AndroidRuntime: FATAL EXCEPTION: main
                                                             Process: package.app.whatever, PID: 23444
10-09 16:47:23.071 2445-2898/? E/Watchdog: !@Sync 4443
10-09 16:47:23.306 2445-24874/? E/android.os.Debug: !@Dumpstate &gt; sdumpstate -k -t -z -d -o /data/log/dumpstate_app_error
</code></pre>

<p>I read that Retrofit throws <code>IOException</code> while no network connection available, but I don't know how to catch it. Here is the proper code:</p>

<pre><code> private void syncOne(){
    RealmResults&lt;CallLog&gt; res = Realm.getDefaultInstance()
            .where(CallLog.class)
            .equalTo(Constants.EXTRA_CALL_LOG_PRIVATE, false)
            .equalTo(Constants.EXTRA_CALL_LOG_DEFAULT_SYNC, true)
            .greaterThan(Constants.EXTRA_CALL_LOG_DATE_EDIT, Utils.getUTCToDate(lastSuccessfulSync))
            .findAll();

    listCallLogs.addAll(res);

    String json = jsonCallLogAdapter.toJson(listCallLogs);

    Log.d("asd-1json1", json);

    Subscription sendLogs = networkClient
            .sendCallLogs(token, RequestBody.create(MediaType.parse("application/json"), json))
            .flatMap(response -&gt; {
                return networkClient.getCallLogsAfterDate(token, lastSuccessfulSync);
            })
            .flatMap(response -&gt;{
                String json2 = "";
                try {
                    json2 = response.body().string();
                    listCallLogs.clear();
                    listCallLogs = jsonCallLogAdapter.fromJson(json2);
                    Log.d("asd-1json2", json2);
                } catch (IOException e){
                    Log.e("IOException", e.toString());
                }

                RealmResults&lt;Contact&gt; res3 = Realm.getDefaultInstance()
                        .where(Contact.class)
                        .equalTo(Constants.EXTRA_CONTACT_PRIVATE, false)
                        .greaterThan(Constants.EXTRA_CONTACT_DATE_EDIT, Utils.getUTCToDate(lastSuccessfulSync))
                        .findAll();
                listContacts.clear();
                listContacts.addAll(res3);

                String json3 = jsonContactAdapter.toJson(listContacts);

                Log.i("asd-1json3", json3);

                return networkClient.sendContacts(token, (RequestBody.create(MediaType.parse("application/json"), json3)));
            })
            .flatMap(response -&gt; {
                return networkClient.getContactsAfterDate(token, lastSuccessfulSync);
            })
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(
                    response -&gt; {
                        stopRefreshing(swipeRefreshLayout);
                        if(response.isSuccessful()){
                            try {
                                Log.d("asd-1json4", response.body().string());
                                SharedPreferences.Editor editor = userdata.edit();
                                editor.putString(Constants.EXTRA_LAST_SYNC, Utils.getDateInUTC(Calendar.getInstance().getTime()));
                                editor.commit();

                                Toast.makeText(c,
                                        c.getResources().getString(R.string.synchronization_database_synced),
                                        Toast.LENGTH_SHORT).show();

                            } catch (IOException e){
                                Log.d("asd-sync-one-error", e.toString());
                            }
                        } else {
                            try{
                                String s = response.errorBody().string();
                                Log.e("asd-server-error", s);
                                Toast.makeText(c,
                                        c.getResources().getString(R.string.synchronization_error_sending_logs_server),
                                        Toast.LENGTH_SHORT).show();

                            } catch (IOException e){
                                e.printStackTrace();
                            }
                        }
                    },
                    error -&gt; {

                        if(error instanceof IOException){

                        }
                        stopRefreshing(swipeRefreshLayout);

                        Toast.makeText(c,
                                c.getResources().getString(R.string.synchronization_error_sending_logs_local),
                                Toast.LENGTH_SHORT).show();

                        Log.e("asd-local-error", error.toString()
                                + "/" + error.getCause()
                                + "/" + error);

                        Crashlytics.logException(error);
                    });
}
</code></pre>