package com.zhaohaoting.framework.requset;

import com.zhaohaoting.framework.mvchelper.okhttp.exception.RequestException;
import com.zhaohaoting.framework.mvchelper.task.Code;
import com.zhaohaoting.framework.mvchelper.task.imp.SimpleCallback;
import com.zhaohaoting.framework.utils.ToastUtils;

/**
 * author：Created by ZHT on 2017/12/8 10:32
 * email：526309416@qq.com
 * desc：数据回调 此处做了请求取消判断
 */
public abstract class NetWorkCallBack<DATA> extends SimpleCallback<DATA> {
    @Override
    public void onPostExecute(Object task, Code code, RequestException exception, DATA data) {
        if (code == Code.CANCEL) return;
        if (code == Code.SUCCESS) {
            onPostExecuteSuccess(task, data);
        } else {
            onPostExecuteFailure(task, exception);
        }
    }

    protected void onPostExecuteFailure(Object task, Exception exception) {
        ToastUtils.show(exception.getMessage());
    }

    protected abstract void onPostExecuteSuccess(Object task, DATA data);
}
