diff --git a/.idea/compiler.xml b/.idea/compiler.xml
index a891a69..e2a5e51 100644
--- a/.idea/compiler.xml
+++ b/.idea/compiler.xml
@@ -7,6 +7,7 @@
+
@@ -14,6 +15,7 @@
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
index 1f93b88..1e86ad3 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -8,5 +8,5 @@
-
+
\ No newline at end of file
diff --git a/src/main/java/com/filesystem/config/GlobalExceptionHandler.java b/src/main/java/com/filesystem/config/GlobalExceptionHandler.java
index a44b76b..2ee1e8a 100644
--- a/src/main/java/com/filesystem/config/GlobalExceptionHandler.java
+++ b/src/main/java/com/filesystem/config/GlobalExceptionHandler.java
@@ -1,13 +1,11 @@
package com.filesystem.config;
+import com.filesystem.utils.ApiResult;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
-import java.io.IOException;
-import java.util.Map;
-
@RestControllerAdvice
public class GlobalExceptionHandler {
@@ -15,29 +13,34 @@ public class GlobalExceptionHandler {
* 处理所有运行时异常
*/
@ExceptionHandler(RuntimeException.class)
- public ResponseEntity> handleRuntimeException(RuntimeException e) {
+ public ApiResult> handleRuntimeException(RuntimeException e) {
e.printStackTrace();
- return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
- .body(Map.of("message", e.getMessage() != null ? e.getMessage() : "服务器内部错误"));
+ return ApiResult.error(e.getMessage() != null ? e.getMessage() : "服务器内部错误");
}
/**
- * 处理 IO 异常(如 ZIP 压缩失败)
+ * 处理参数异常
*/
- @ExceptionHandler(IOException.class)
- public ResponseEntity> handleIOException(IOException e) {
+ @ExceptionHandler(IllegalArgumentException.class)
+ public ApiResult> handleIllegalArgumentException(IllegalArgumentException e) {
+ return ApiResult.error(e.getMessage() != null ? e.getMessage() : "请求参数错误");
+ }
+
+ /**
+ * 处理 IO 异常(如文件操作失败)
+ */
+ @ExceptionHandler(java.io.IOException.class)
+ public ApiResult> handleIOException(java.io.IOException e) {
e.printStackTrace();
- return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
- .body(Map.of("message", "文件操作失败: " + (e.getMessage() != null ? e.getMessage() : "未知错误")));
+ return ApiResult.error("文件操作失败: " + (e.getMessage() != null ? e.getMessage() : "未知错误"));
}
/**
* 处理所有其他异常
*/
@ExceptionHandler(Exception.class)
- public ResponseEntity> handleException(Exception e) {
+ public ApiResult> handleException(Exception e) {
e.printStackTrace();
- return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
- .body(Map.of("message", "服务器错误: " + (e.getMessage() != null ? e.getMessage() : "未知错误")));
+ return ApiResult.serverError(e.getMessage() != null ? e.getMessage() : "未知错误");
}
}
diff --git a/src/main/java/com/filesystem/controller/AuthController.java b/src/main/java/com/filesystem/controller/AuthController.java
index 7dffca2..a7f3eb2 100644
--- a/src/main/java/com/filesystem/controller/AuthController.java
+++ b/src/main/java/com/filesystem/controller/AuthController.java
@@ -3,8 +3,8 @@ package com.filesystem.controller;
import com.filesystem.entity.User;
import com.filesystem.security.UserPrincipal;
import com.filesystem.service.UserService;
+import com.filesystem.utils.ApiResult;
import jakarta.annotation.Resource;
-import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.*;
@@ -19,7 +19,7 @@ public class AuthController {
private UserService userService;
@PostMapping("/login")
- public ResponseEntity> login(@RequestBody Map request) {
+ public ApiResult