Improve SFTP file view and upload handling
Add hidden-file toggle and search, prevent rapid-click path duplication, fix multipart upload headers, and raise backend upload size limits with clearer errors.
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
package com.sshmanager.exception;
|
||||
|
||||
import org.apache.tomcat.util.http.fileupload.impl.FileSizeLimitExceededException;
|
||||
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 org.springframework.web.multipart.MaxUploadSizeExceededException;
|
||||
import org.springframework.web.multipart.MultipartException;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@RestControllerAdvice
|
||||
public class GlobalExceptionHandler {
|
||||
|
||||
@ExceptionHandler(MaxUploadSizeExceededException.class)
|
||||
public ResponseEntity<Map<String, String>> handleMaxUploadSize(MaxUploadSizeExceededException e) {
|
||||
Map<String, String> err = new HashMap<>();
|
||||
err.put("error", "上传失败:文件大小超过限制");
|
||||
return ResponseEntity.status(HttpStatus.PAYLOAD_TOO_LARGE).body(err);
|
||||
}
|
||||
|
||||
@ExceptionHandler(MultipartException.class)
|
||||
public ResponseEntity<Map<String, String>> handleMultipart(MultipartException e) {
|
||||
Throwable root = e;
|
||||
while (root.getCause() != null && root.getCause() != root) {
|
||||
root = root.getCause();
|
||||
}
|
||||
|
||||
if (root instanceof FileSizeLimitExceededException
|
||||
|| (root.getMessage() != null && root.getMessage().contains("exceeds its maximum permitted size"))) {
|
||||
Map<String, String> err = new HashMap<>();
|
||||
err.put("error", "上传失败:文件大小超过限制");
|
||||
return ResponseEntity.status(HttpStatus.PAYLOAD_TOO_LARGE).body(err);
|
||||
}
|
||||
|
||||
Map<String, String> err = new HashMap<>();
|
||||
err.put("error", "上传失败:表单解析异常");
|
||||
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(err);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user