package com.fdkanfang.common.exception;

import com.fdkanfang.common.enums.ResultCodeEnum;
import lombok.Data;

/**
 * @author abnerhou
 * @date 2020/5/25 11:39
 * @desciption
 */
@Data
public class CommonBaseException extends RuntimeException{
    private static final long serialVersionUID = 2899335020273674737L;

    private Integer code;

    private String msg;

    public CommonBaseException(Integer code, String msg){
        super(msg);
        this.code = code;
        this.msg = msg;
    }


    public CommonBaseException(ResultCodeEnum resultCodeEnum){
        super(resultCodeEnum.getDesc());
        this.code = resultCodeEnum.getCode();
        this.msg = resultCodeEnum.getDesc();
    }

    public CommonBaseException(ResultCodeEnum resultCodeEnum , String replaceMsg){
        super(resultCodeEnum.getDesc());
        this.code = resultCodeEnum.getCode();
        if(resultCodeEnum.getCanBeReplace()){
            this.msg = replaceMsg;
        }else{
            this.msg = resultCodeEnum.getDesc();
        }
    }




}
