androidexceptionbroadcastreceiverevent-busgeneral-network-error

how to avoid EventBus Exception (Android)?


I"m working on existing application and they are using EventBus that get every network exception like this :

  public void onEvent(final NetworkErrorEvent event) {
    runOnUiThread(new Runnable() {

        @Override
        public void run() {

            Log.e("EventBus Event" + "(IOException)");

            if (event.getType() == NetworkError.Timeout) {
                L.e("timeout");
            } else if (event.getType() == NetworkError.Disconnected) {
                L.e("disconnected");
            } else if (event.getType() == NetworkError.UnknownHost) {
                L.e("UnknownHost");
            }

             showConnectionErrorDialog(event.getType(), true);
        }
    });
}

i want to add api call that i don't want to notify EventBus if failed , how it can be done ?

i don't see eventBus.post(event) in my project , the code i wrote is capture every network error even if i don't want him to .


Solution

  • The NetworkErrorEvent is not part of the EventBus - I suggest finding out where it comes from and starting there. I suspect it may be custom code wrapping something from Retrofit.

    The EventBus is perfect for something like logging network failures because you can fire the events off everywhere in your code, and then simply choose to handle those events somewhere, or even multiple places, or nowhere..