package cn.meowrain.aioj.backend.framework.core.exception;

import cn.meowrain.aioj.backend.framework.core.errorcode.IErrorCode;
import lombok.Getter;
import org.springframework.util.StringUtils;

import java.util.Optional;

/**
 * 抽象错误处理Exception,基于这个抽象类，我们能创建很多其它类型的exception，定义错误类型
 */
@Getter

public class AbstractException extends RuntimeException {

	public final String errorCode;

	public final String errorMessage;

	public AbstractException(String message, Throwable throwable, IErrorCode errorCode) {
		super(message);
		this.errorCode = errorCode.code();
		this.errorMessage = Optional.ofNullable(StringUtils.hasLength(message) ? message : null)
			.orElse(errorCode.message());
	}

}
