|
@@ -1,6 +1,7 @@
|
|
|
package com.etotem.cfc.config;
|
|
package com.etotem.cfc.config;
|
|
|
|
|
|
|
|
import com.etotem.cfc.common.Result;
|
|
import com.etotem.cfc.common.Result;
|
|
|
|
|
+import java.io.IOException;
|
|
|
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;
|
|
@@ -39,6 +40,14 @@ public class GlobalExceptionHandler {
|
|
|
return Result.error(400, "请求参数格式错误");
|
|
return Result.error(400, "请求参数格式错误");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ // 客户端中断连接(Broken pipe / ClientAbortException):连接已断开,无法写响应,
|
|
|
|
|
+ // 只记录日志,避免在 @ExceptionHandler 中二次抛异常导致 "Failure in @ExceptionHandler"
|
|
|
|
|
+ @ExceptionHandler(IOException.class)
|
|
|
|
|
+ public Result<Void> handleClientAbort(IOException e, HttpServletRequest request) {
|
|
|
|
|
+ log.warn("客户端连接中断: uri={}, error={}", request.getRequestURI(), e.getMessage());
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
@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);
|