'Retrofit not returning, event when the response is 200

I can see. the response from the logs since I have added a logger to my okhttp3 client, but for some reason, nothing happens after that. No error, nothing. I have tried on the virtual device and the physical one. retrofit 2.3, gson 2.8.6 Here is my interceptor

@Override
public Response intercept(@NonNull Chain chain) throws IOException {

    try {
        Response response = chain.proceed(chain.request());
        Request request = chain.request();

        AppLogger.d("url from interceptor:" + response.request().url());
        AppLogger.d("request headers from interceptor:" + response.request().headers());
        AppLogger.d("response code from interceptor:" + response.code());
        int responseCode = response.code();
        String oldToken = mPreferencesHelper.getToken();
        if (responseCode == ERROR_NETWORK) {
            showNetworkError();
        } else if (responseCode == 401 || responseCode == 403) {
            if (oldToken != null || request.header(ApiStatics.HEADER_AUTHORIZATION_HEADER) != null) {
                tryRefreshToken();
                response = chain.proceed(request);

            } else {
                openAuthActivity();
            }
        } else if (!response.isSuccessful()) {
            if (response.body() != null) {

                try {

                    onWeoutResponseErrorListener.onNext(response.body());
                } catch (OnErrorNotImplementedException e) {
                    AppLogger.d(e, "ServerResponseInterceptor");
                } catch (NullPointerException e) {
                    AppLogger.d(e, "ServerResponseINterceptor");
                }
            } else AppLogger.e(new NullPointerException(), "server returned no body ");
        }
        return response;
    }catch (NullPointerException e){
        AppLogger.d(e, "ServerResponseInterceptor");
        openAuthActivity();

        Response.Builder responseBuilder = new Response.Builder();
        responseBuilder.code(404).message(e.getMessage()).request(chain.request()).protocol(Protocol.HTTP_2);
        return  responseBuilder.build();
    }

}

I can see all the logs from both AppLogger and the interceptor I added on Okhttp3 client. But neither onResponse nor OnFailure get called.

My request below

Call<PlaceListResponse> call = dataManager.getApiHelper().getPlacesApiHelper().getPlaces(pagePlace, searchQuery, null, mPlaceFilter, null, null, null);
    AppLogger.d(call.request().url().host());
    call.enqueue(new Callback<PlaceListResponse>() {
        @Override
        public void onResponse(@NonNull Call<PlaceListResponse> call, @NonNull Response<PlaceListResponse> response) {
            updateLoadingStatus(false);
            isLoadingNextPagePlaces.postValue(false);
            AppLogger.d(TAG + " response places: " + response.body());
            if (response.code() == 200) {
                if (response.body() != null) {
                    PlaceListResponse responseBody = response.body();
                    hasNextPlacesPage = responseBody.getNext() != null;
                    List<PlaceListResult> places = responseBody.getResults();
                    if (places.size() > 0 & places.size() >10) places = places.subList(0,11);
                    List<WeOutItemViewModel> placesViewModels = WeOutPlacesViewModel.this.getPlaceItemViewModels(places);
                    List<Double> sortedDistances = WeOutPlacesViewModel.this.getSortedDistances(placesViewModels);
                    List<WeOutGroupedViewModels> weOutGroupedViewModels = 
getGroupedViewModels(placesViewModels,
sortedDistances);
                    updateReceiver.postValue(weOutGroupedViewModels);
                } else {
                    AppLogger.d(TAG + " nothing loaded");
                }

            } else if (response.code() >= 400 && response.code() < 500 && response.code() != 404) {
                Timber.d("unregistered:", response.message());
                unregisteredAction();
            } else { //                    TODO:
                Timber.d("event error", response.toString(), WeOutViewModel.class.getName());
                Timber.e("event error" + response.code());
                Timber.e("event response header" + response.headers());
                Timber.e("event request header" + response.raw().request().headers());
                Timber.e("event request header" + response.raw().request().header("Authorization"));
            }
        }

        @Override
        public void onFailure(Call<PlaceListResponse> call, Throwable t) {
            updateLoadingStatus(false); //                isLoadingPlaces.set(false);
            isLoadingNextPagePlaces.postValue(false);
            Timber.e(TAG + t.getMessage() + "error loading places");
            Timber.e(t, TAG);
            call.cancel();
            errorListener.postValue(ERROR_NETWORK);
        }
    });


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source