package com.yunfeiyun.agmp.common.exception;

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

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

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

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

    /**
     * 错误消息
     */
    private String msg;
    public BaseException(String code,  String msg ,Object data)
    {
        this.code = code;
        this.data = data;
        this.msg = msg;
    }

    public BaseException(ErrorCode errorCode){
        this.code = errorCode.getCode();
        this.msg = errorCode.getMessage();
    }

    public BaseException(ErrorCode errorCode,Object data){
        this.code = errorCode.getCode();
        this.msg = errorCode.getMessage();
        this.data = data;
    }

    @Override
    public String getMessage()
    {
        String message = "未知错误";
        if (!StringUtils.isEmpty(this.msg))
        {
            message = this.msg;
        }
        return message;
    }

    public String getCode()
    {
        return code;
    }

    public Object getData()
    {
        return data;
    }

    public String getMsg()
    {
        return msg;
    }
}
