package com.ycgis.macall.personalcenter.p.callback;


import com.ycgis.macall.personalcenter.p.request.HttpErrorHandler;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author macall
 * @Create 2020/1/7 0007
 * @Describe
 */
public abstract class BaseRequestCallback<T> implements RequestCallback<T> {
    /*========================= HttpException 异常 code ==========================*/

    private List<Object> payloads;

    public BaseRequestCallback() {
    }

    public BaseRequestCallback(List<Object> payloads) {
        this.payloads = payloads;
    }

    public BaseRequestCallback<T> addPayload(Object o){
        if (payloads==null){
            payloads = new ArrayList<>();
        }
        payloads.add(o);
        return this;
    }

    public List<Object> getPayloads() {
        return payloads;
    }

    @Override
    public void onRequestFailure(Throwable e) {
        onRequestFailure(HttpErrorHandler.requestHandle(e));
    }

    public abstract void onRequestFailure(String msg);

    @Override
    public void onStartRequest() {

    }


}
