com.taxjar.net.ApiCallback Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of taxjar-java Show documentation
Show all versions of taxjar-java Show documentation
TaxJar Java Sales Tax API Client
The 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));
}
}