Search code examples
androidretrofitrobospice

Catch Error in RetrofitError and pass it to RoboSpice Error


I am using the Retrofit module provided by Robospice. I am making asynchronous retrofit calls. The problem is that if my call is unsuccessful I get a Retrofit Error but in robospice I am getting the the feedback in onSuccess and not in onFailure(RobospiceException).

I am using the following code to execute my webservice call.

mSpiceManager.execute(mProfileRequest, new ProfileRequestListener());

The loaddatafromnetwork call in ProfileRequest is as follows:

@Override
public Profile loadDataFromNetwork() throws Exception {
    initCountDownLatch();
    //Adding a retrofit callback.
    getService().getProfile("//profileid", new AbstractCallback<Profile>() {
        @Override
        public void success(Profile profile, Response response) {
            super.success(profile, response);
            ProfileRequest.this.profile = profile;
            mCountDownLatch.countDown();
        }

        @Override
        public void failure(RetrofitError retrofitError) {
            super.failure(retrofitError);
            mCountDownLatch.countDown();
        }
    });
    mCountDownLatch.await();
    return profile;
}

Can anyone let me know how can Robospice see get onFailure ? In simple words has anyone tried implmenting robospice with retrofit "Asynchronous calls"(With Retrofit callback implemented") ?


Solution

  • you should throw the RetrofitError in failure().