37 lines
896 B
Java
37 lines
896 B
Java
|
|
package com.competition.common.exception;
|
||
|
|
|
||
|
|
import com.competition.common.enums.ErrorCode;
|
||
|
|
import lombok.Getter;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 业务异常
|
||
|
|
*/
|
||
|
|
@Getter
|
||
|
|
public class BusinessException extends RuntimeException {
|
||
|
|
|
||
|
|
private final Integer code;
|
||
|
|
|
||
|
|
public BusinessException(Integer code, String message) {
|
||
|
|
super(message);
|
||
|
|
this.code = code;
|
||
|
|
}
|
||
|
|
|
||
|
|
public BusinessException(ErrorCode errorCode) {
|
||
|
|
super(errorCode.getMessage());
|
||
|
|
this.code = errorCode.getCode();
|
||
|
|
}
|
||
|
|
|
||
|
|
public BusinessException(ErrorCode errorCode, String message) {
|
||
|
|
super(message);
|
||
|
|
this.code = errorCode.getCode();
|
||
|
|
}
|
||
|
|
|
||
|
|
public static BusinessException of(ErrorCode errorCode) {
|
||
|
|
return new BusinessException(errorCode);
|
||
|
|
}
|
||
|
|
|
||
|
|
public static BusinessException of(ErrorCode errorCode, String message) {
|
||
|
|
return new BusinessException(errorCode, message);
|
||
|
|
}
|
||
|
|
}
|