All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.taxjar.net.ApiCallback Maven / Gradle / Ivy

There is a newer version: 5.0.3
Show newest version
package com.taxjar.net;

import com.taxjar.exception.ApiConnectionException;
import com.taxjar.exception.TaxjarException;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

import java.io.IOException;

public class ApiCallback implements Callback {
    protected Listener apiListener;

    public ApiCallback(Listener listener) {
        apiListener = listener;
    }

    @Override
    public void onResponse(Call call, Response response) {
        if (response.isSuccessful()) {
            apiListener.onSuccess(response.body());
        } else {
            try {
                apiListener.onError(new TaxjarException(response.errorBody().string()));
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    @Override
    public void onFailure(Call call, Throwable t) {
        apiListener.onError(new ApiConnectionException(t.getMessage(), t));
    }
}





© 2015 - 2024 Weber Informatics LLC | Privacy Policy