feat: 自定义异常消息支持占位符
This commit is contained in:
@@ -2,11 +2,12 @@ package com.youlai.system.common.exception;
|
|||||||
|
|
||||||
import com.youlai.system.common.result.IResultCode;
|
import com.youlai.system.common.result.IResultCode;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
import org.slf4j.helpers.MessageFormatter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 自定义业务异常
|
* 自定义业务异常
|
||||||
*
|
*
|
||||||
* @author haoxr
|
* @author Ray Hao
|
||||||
* @since 2022/7/31
|
* @since 2022/7/31
|
||||||
*/
|
*/
|
||||||
@Getter
|
@Getter
|
||||||
@@ -19,10 +20,6 @@ public class BusinessException extends RuntimeException {
|
|||||||
this.resultCode = errorCode;
|
this.resultCode = errorCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
public BusinessException(String message){
|
|
||||||
super(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
public BusinessException(String message, Throwable cause) {
|
public BusinessException(String message, Throwable cause) {
|
||||||
super(message, cause);
|
super(message, cause);
|
||||||
}
|
}
|
||||||
@@ -31,5 +28,11 @@ public class BusinessException extends RuntimeException {
|
|||||||
super(cause);
|
super(cause);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public BusinessException(String message, Object... args) {
|
||||||
|
super(formatMessage(message, args));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String formatMessage(String message, Object... args) {
|
||||||
|
return MessageFormatter.arrayFormat(message, args).getMessage();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user