package com.yunfeiyun.agmp.common.exception;

import com.yunfeiyun.agmp.common.constant.ErrorCode;
import com.yunfeiyun.agmp.common.utils.MessageUtils;
import com.yunfeiyun.agmp.common.utils.StringUtils;

/**
 * 基础异常
 * 
 * @author 杨晓辉
 */
public class BaseException extends RuntimeException
{
    private static final long serialVersionUID = 1L;

    /**
     * 错误码
     */
    private String code;



    /**
     * 错误码对应的参数
     */
    private Object[] data;

    /**
     * 错误消息
     */
    private String msg;
    private String msgKey = "-1";  //没有变量的类型
    public BaseException(String code,  String msg , String msgKey ,Object[] data)
    {
        this.code = code;
        this.data = data;
        this.msg = msg;
        this.msgKey = msgKey;
    }
    public BaseException(ErrorCode errorCode){
        this.code = errorCode.getCode();
        this.msg = errorCode.getMessage();
        this.msgKey = "-1";
    }


    @Override
    public String getMessage()
    {
        String message = null;
        if (!StringUtils.isEmpty(msg))
        {
            if("-1".equalsIgnoreCase(msgKey))
                message = this.msg; //解析文件错误码 this.msg;
            else
                message = "未知错误";
        }
        if (message == null)
        {
            message = msg;
        }
        return message;
    }

    public String getCode()
    {
        return code;
    }

    public Object getData()
    {
        return data;
    }

    public String getMsg()
    {
        return msg;
    }
}
