mirror of
https://gitee.com/dromara/RuoYi-Vue-Plus.git
synced 2026-09-21 02:25:56 +08:00
Pre Merge pull request !217 from Yjoioooo/auto-5403234-dev-b942dd9b
This commit is contained in:
commit
50d9c9c76b
@ -22,6 +22,9 @@ import org.springframework.web.bind.annotation.RestControllerAdvice;
|
|||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.validation.ConstraintViolation;
|
import javax.validation.ConstraintViolation;
|
||||||
import javax.validation.ConstraintViolationException;
|
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)
|
@ExceptionHandler(ServiceException.class)
|
||||||
public R<Void> handleServiceException(ServiceException e, HttpServletRequest request) {
|
public R<Void> handleServiceException(ServiceException e, HttpServletRequest request) {
|
||||||
|
filterStackTrace(e, "com.ruoyi");
|
||||||
log.error(e.getMessage(), e);
|
log.error(e.getMessage(), e);
|
||||||
Integer code = e.getCode();
|
Integer code = e.getCode();
|
||||||
return ObjectUtil.isNotNull(code) ? R.fail(code.intValue(), e.getMessage()) : R.fail(e.getMessage());
|
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) {
|
public R<Void> handleDemoModeException(DemoModeException e) {
|
||||||
return R.fail("演示模式,不允许操作");
|
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