You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
54 lines
1.4 KiB
54 lines
1.4 KiB
package com.stone.conf.exception;
|
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
import com.stone.api.enums.BusinessExceptionEnum;
|
|
import com.stone.api.enums.ResultCode;
|
|
import lombok.Data;
|
|
import lombok.EqualsAndHashCode;
|
|
|
|
@EqualsAndHashCode(callSuper = true)
|
|
@Data
|
|
public class BusinessException extends RuntimeException {
|
|
|
|
private static final long serialVersionUID = 194906846739586856L;
|
|
|
|
protected String code;
|
|
|
|
protected String message;
|
|
|
|
protected ResultCode resultCode;
|
|
|
|
protected Object data;
|
|
|
|
public BusinessException() {
|
|
BusinessExceptionEnum exceptionEnum = BusinessExceptionEnum.getByEClass(this.getClass());
|
|
if (exceptionEnum != null) {
|
|
resultCode = exceptionEnum.getResultCode();
|
|
code = exceptionEnum.getResultCode().code().toString();
|
|
message = exceptionEnum.getResultCode().message();
|
|
}
|
|
|
|
}
|
|
|
|
public BusinessException(String message) {
|
|
this();
|
|
this.message = message;
|
|
}
|
|
|
|
public BusinessException(String format, Object... objects) {
|
|
this();
|
|
this.message = StrUtil.format(format, "{}", objects);
|
|
}
|
|
|
|
public BusinessException(ResultCode resultCode, Object data) {
|
|
this(resultCode);
|
|
this.data = data;
|
|
}
|
|
|
|
public BusinessException(ResultCode resultCode) {
|
|
this.resultCode = resultCode;
|
|
this.code = resultCode.code().toString();
|
|
this.message = resultCode.message();
|
|
}
|
|
|
|
}
|