package com.inkasso.adapter.exception;

import com.inkasso.adapter.util.CodeUtil;
import com.inkasso.factoring.common.entity.ResponseJson;

import java.util.Map;

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

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

    /**
     * @param code 错误代号
     * @param msg  错误提示
     */
    public BusinessException(Integer 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;
    }
}
