ソースを参照

fix(exception): 处理资源未找到异常并移除调试日志

- 添加 NoResourceFoundException 异常处理器
- 移除 mapper 层的 debug 日志配置
- 优化全局异常处理逻辑
ChenYu 6 ヶ月 前
親
コミット
08d1c09caa

+ 9 - 1
src/main/java/com/aitori/exception/GlobalExceptionHandle.java

@@ -1,15 +1,17 @@
 package com.aitori.exception;
 
-import com.dtflys.forest.exceptions.ForestRuntimeException;
 import com.aitori.annotation.SkipResponseWrapper;
 import com.aitori.dto.R;
+import com.dtflys.forest.exceptions.ForestRuntimeException;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
 import org.springframework.web.bind.MethodArgumentNotValidException;
 import org.springframework.web.bind.annotation.ControllerAdvice;
 import org.springframework.web.bind.annotation.ExceptionHandler;
 import org.springframework.web.bind.annotation.ResponseBody;
 import org.springframework.web.bind.annotation.ResponseStatus;
+import org.springframework.web.servlet.resource.NoResourceFoundException;
 
 import java.util.HashMap;
 import java.util.Map;
@@ -48,6 +50,12 @@ public class GlobalExceptionHandle {
         return R.fail(HttpStatus.BAD_REQUEST.value(), e.getMessage());
     }
 
+    @ExceptionHandler(NoResourceFoundException.class)
+    public R<Void> handleNoResourceFound() {
+        // 直接返回404,不打印任何异常
+        return R.fail(HttpStatus.NOT_FOUND.value(), "Resource not found");
+    }
+
     @ExceptionHandler(value = Exception.class)
     @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
     public R<Void> exceptionHandle(Exception e) {

+ 0 - 1
src/main/resources/application.yaml

@@ -42,7 +42,6 @@ mybatis-plus:
 logging:
   level:
     com.aitori: info
-    com.aitori.mapper: debug
 
 # --- doc ---
 springdoc: