package com.face.global.exception;

public class BusinessException extends RuntimeException {
    private String code;

    private String message;

    private BusinessException realBusinessException;

    public BusinessException(String code, String message) {
        this.code = code;
        this.message = message;
    }

    public BusinessException(String code, String message, Throwable cause) {
        super(cause);
        this.code = code;
        this.message = message;
        if (cause instanceof BusinessException && this.realBusinessException == null) {
            this.realBusinessException = this;
        }
    }

    public String getCode() {
        if (this.realBusinessException != null && this != this.realBusinessException) {
            return this.realBusinessException.getCode();
        }
        return code;
    }

    @Override
    public String getMessage() {
        if (this.realBusinessException != null && this != this.realBusinessException) {
            return this.realBusinessException.getMessage();
        }
        return message;
    }
}
