|
|
@@ -1,10 +1,12 @@
|
|
|
package com.etotem.cfc.config;
|
|
|
|
|
|
import com.etotem.cfc.common.Result;
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.web.bind.annotation.ExceptionHandler;
|
|
|
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
|
|
+import org.springframework.web.multipart.MultipartException;
|
|
|
|
|
|
@RestControllerAdvice
|
|
|
public class GlobalExceptionHandler {
|
|
|
@@ -16,9 +18,15 @@ public class GlobalExceptionHandler {
|
|
|
return Result.error(400, e.getMessage());
|
|
|
}
|
|
|
|
|
|
+ @ExceptionHandler(MultipartException.class)
|
|
|
+ public Result<Void> handleMultipartException(MultipartException e, HttpServletRequest request) {
|
|
|
+ log.warn("非multipart请求访问文件接口: uri={}, error={}", request.getRequestURI(), e.getMessage());
|
|
|
+ return Result.error(400, "请求格式错误,请使用文件表单上传");
|
|
|
+ }
|
|
|
+
|
|
|
@ExceptionHandler(Exception.class)
|
|
|
- public Result<Void> handleException(Exception e) {
|
|
|
- log.error("未捕获异常: {} - {}", e.getClass().getName(), e.getMessage(), e);
|
|
|
+ public Result<Void> handleException(Exception e, HttpServletRequest request) {
|
|
|
+ log.error("未捕获异常: {} - {} | uri={}", e.getClass().getName(), e.getMessage(), request.getRequestURI(), e);
|
|
|
return Result.error("服务器内部错误");
|
|
|
}
|
|
|
}
|