package com.sunxung.factoring.component.exception;

import java.util.Map;

import com.sunxung.factoring.component.util.CodeUtil;
import com.sunxung.factoring.entity.ResponseJson;

/** 业务异常 */
public class BusinessException extends RuntimeException {

    private static final long serialVersionUID = 1L;
    /** 错误数据提示 */
    private ResponseJson responseJson;

    /**
     * @param code 错误代号
     * @param msg 错误提示
     */
    public BusinessException(String code, String msg){
        super(msg);
        responseJson = new ResponseJson(code, msg);
    }

    public BusinessException(Map<String, String> errors){
        super(errors.toString());
        responseJson = new ResponseJson();
        responseJson.setMsg(errors);
        responseJson.setCode(CodeUtil.PARAMETER_ERROR);
        responseJson.setSuccess(false);
    }

    /** 获取验证错误数据 */
    public ResponseJson getResponseJson() {
        return responseJson;
    }
}
