package com.mortals.xhx.module.api.feign.portal;

import com.mortals.framework.exception.AppException;

import java.util.Collections;


public class BusinesException extends AppException {

	private static final long serialVersionUID = 1L;
	
	private Object data = Collections.emptyMap();
	

	public Object getData() {
		return data;
	}

	public static void throwError (ApiResponseCode code) {
		throw new BusinesException(code);
	}

	public static void throwError (int code, String msg) {
		throw new BusinesException(code, msg);
	}

	public static void throwError (ApiResponseCode code, Object data) {
		throw new BusinesException(code, data);
	}

	public BusinesException(int code, String msg) {
		super(code, msg);
	}

	public BusinesException(int code, String msg, Object data) {
		super(code, msg);
		this.data = data;
	}


	public BusinesException(ApiResponseCode code) {
		this(code.getCode(), code.getDesc());
	}
	
	public BusinesException(ApiResponseCode code, Object data) {
		this(code.getCode(), code.getDesc());
		this.data = data;
	}

	/**
	 * 重写堆栈填充，不填充错误堆栈信息，提高性能
	 * @return
	 */
	@Override
	public Throwable fillInStackTrace() {
		return this;
	}

}
