package com.goafanti.common.error;

import com.goafanti.common.bo.Error;

public class BusinessException extends RuntimeException {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1889327507120174994L;

	private Error error;

	/**
	 * Creates a new BusinessException.
	 */
	public BusinessException() {
		super();
	}

	/**
	 * Constructs a new BusinessException.
	 * 
	 * @param message
	 *            the reason for the exception
	 */
	public BusinessException(String message) {
		super(message);
	}

	/**
	 * Constructs a new BusinessException.
	 * 
	 * @param cause
	 *            the underlying Throwable that caused this exception to be
	 *            thrown.
	 */
	public BusinessException(Throwable cause) {
		super(cause);
	}

	/**
	 * Constructs a new BusinessException.
	 * 
	 * @param message
	 *            the reason for the exception
	 * @param cause
	 *            the underlying Throwable that caused this exception to be
	 *            thrown.
	 */
	public BusinessException(String message, Throwable cause) {
		super(message, cause);
	}

	/**
	 * Constructs a new BusinessException.
	 * 
	 * @param error
	 *            the error for the exception
	 */
	public BusinessException(Error error) {
		super(error.getMessage());
		this.error = error;
	}

	/**
	 * Constructs a new BusinessException.
	 * 
	 * @param error
	 *            the error for the exception
	 * @param cause
	 *            the underlying Throwable that caused this exception to be
	 *            thrown.
	 */
	public BusinessException(Error error, Throwable cause) {
		super(error.getMessage(), cause);
		this.error = error;
	}

	public String getCode() {
		return error == null ? "" : error.getCode();
	}

	public String getField() {
		return error == null ? "" : error.getField();
	}
}
