rk
昨天 4a8ff39b0fab0627ef8f7459587d514cc01c3676
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package com.doumee.lib_coremodel.http.callback;
 
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.HttpException;
import retrofit2.Response;
import timber.log.Timber;
 
/**
 * @author <a href="mailto:jenly1314@gmail.com">Jenly</a>
 */
public abstract class ApiCallback<T> implements Callback<T> {
    @Override
    public void onResponse(Call<T> call, Response<T> response) {
        if(response.isSuccessful()){
            T result = response.body();
            Timber.d("Response:" + result);
            onResponse(call,result);
        }else{
            onError(call,new HttpException(response));
        }
    }
 
    @Override
    public void onFailure(Call<T> call, Throwable t) {
        Timber.w(t);
        onError(call,t);
    }
 
    public abstract void onResponse(Call<T> call, T result);
 
    public abstract void onError(Call<T> call, Throwable t);
}