mirror of
https://gitee.com/dromara/RuoYi-Vue-Plus.git
synced 2026-09-20 18:15:56 +08:00
add 新增全局异常处理堆栈过滤方法,精简ServiceException异常输出
This commit is contained in:
parent
d1681dc18c
commit
049bbdd179
@ -22,6 +22,9 @@ import org.springframework.web.bind.annotation.RestControllerAdvice;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.validation.ConstraintViolation;
|
||||
import javax.validation.ConstraintViolationException;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 全局异常处理器
|
||||
@ -103,6 +106,7 @@ public class GlobalExceptionHandler {
|
||||
*/
|
||||
@ExceptionHandler(ServiceException.class)
|
||||
public R<Void> handleServiceException(ServiceException e, HttpServletRequest request) {
|
||||
filterStackTrace(e, "com.ruoyi");
|
||||
log.error(e.getMessage(), e);
|
||||
Integer code = e.getCode();
|
||||
return ObjectUtil.isNotNull(code) ? R.fail(code.intValue(), e.getMessage()) : R.fail(e.getMessage());
|
||||
@ -165,4 +169,13 @@ public class GlobalExceptionHandler {
|
||||
public R<Void> handleDemoModeException(DemoModeException e) {
|
||||
return R.fail("演示模式,不允许操作");
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据包名过滤堆栈
|
||||
* @param e Exception
|
||||
* @param packageName 包名
|
||||
*/
|
||||
private void filterStackTrace(Exception e, String packageName) {
|
||||
e.setStackTrace(Arrays.stream(e.getStackTrace()).filter(item -> item.getClassName().contains(packageName) && item.getFileName().contains(".java")).toArray(StackTraceElement[]::new));
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user