云文件管理系统上传组件优化

This commit is contained in:
2026-04-02 12:11:31 +08:00
parent 3710e98eb3
commit 85703d02bf
2 changed files with 141 additions and 0 deletions

View File

@@ -0,0 +1,43 @@
package com.filesystem.config;
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 {
/**
* 处理所有运行时异常
*/
@ExceptionHandler(RuntimeException.class)
public ResponseEntity<?> handleRuntimeException(RuntimeException e) {
e.printStackTrace();
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
.body(Map.of("message", e.getMessage() != null ? e.getMessage() : "服务器内部错误"));
}
/**
* 处理 IO 异常(如 ZIP 压缩失败)
*/
@ExceptionHandler(IOException.class)
public ResponseEntity<?> handleIOException(IOException e) {
e.printStackTrace();
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
.body(Map.of("message", "文件操作失败: " + (e.getMessage() != null ? e.getMessage() : "未知错误")));
}
/**
* 处理所有其他异常
*/
@ExceptionHandler(Exception.class)
public ResponseEntity<?> handleException(Exception e) {
e.printStackTrace();
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
.body(Map.of("message", "服务器错误: " + (e.getMessage() != null ? e.getMessage() : "未知错误")));
}
}