|
@@ -4,6 +4,7 @@ import com.etotem.cfc.common.Result;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
+import org.springframework.web.HttpRequestMethodNotSupportedException;
|
|
|
import org.springframework.web.bind.annotation.ExceptionHandler;
|
|
import org.springframework.web.bind.annotation.ExceptionHandler;
|
|
|
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
|
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
|
|
import org.springframework.web.multipart.MultipartException;
|
|
import org.springframework.web.multipart.MultipartException;
|
|
@@ -24,6 +25,13 @@ public class GlobalExceptionHandler {
|
|
|
return Result.error(400, "请求格式错误,请使用文件表单上传");
|
|
return Result.error(400, "请求格式错误,请使用文件表单上传");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ // 旧客户端用 GET 等废弃方法调用已统一为 POST 的接口(如 /api/notices/list),返回干净的 405,不打错误栈
|
|
|
|
|
+ @ExceptionHandler(HttpRequestMethodNotSupportedException.class)
|
|
|
|
|
+ public Result<Void> handleMethodNotSupported(HttpRequestMethodNotSupportedException e, HttpServletRequest request) {
|
|
|
|
|
+ log.warn("请求方法不支持: uri={}, method={}", request.getRequestURI(), e.getMethod());
|
|
|
|
|
+ return Result.error(405, "请求方法不支持,本平台接口统一使用POST");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
@ExceptionHandler(Exception.class)
|
|
@ExceptionHandler(Exception.class)
|
|
|
public Result<Void> handleException(Exception e, HttpServletRequest request) {
|
|
public Result<Void> handleException(Exception e, HttpServletRequest request) {
|
|
|
log.error("未捕获异常: {} - {} | uri={}", e.getClass().getName(), e.getMessage(), request.getRequestURI(), e);
|
|
log.error("未捕获异常: {} - {} | uri={}", e.getClass().getName(), e.getMessage(), request.getRequestURI(), e);
|