From 46926c971cf01bb31d5775e9658f56f2d1cf21eb Mon Sep 17 00:00:00 2001 From: tianyongbao Date: Mon, 22 Dec 2025 22:46:51 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- intc-admin/Dockerfile | 6 ++++ .../web/handler/GlobalExceptionHandler.java | 36 +++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/intc-admin/Dockerfile b/intc-admin/Dockerfile index ddc2149..e0c7b86 100644 --- a/intc-admin/Dockerfile +++ b/intc-admin/Dockerfile @@ -5,6 +5,12 @@ FROM openjdk:17 LABEL maintainer="Intc" +# 安装字体库,解决验证码生成时的字体加载问题 +RUN apt-get update && apt-get install -y \ + fontconfig \ + fonts-dejavu-core \ + && rm -rf /var/lib/apt/lists/* + RUN mkdir -p /intc/server/logs \ /intc/server/temp \ /intc/skywalking/agent diff --git a/intc-common/intc-common-web/src/main/java/com/intc/common/web/handler/GlobalExceptionHandler.java b/intc-common/intc-common-web/src/main/java/com/intc/common/web/handler/GlobalExceptionHandler.java index 08b1b31..4259e4c 100644 --- a/intc-common/intc-common-web/src/main/java/com/intc/common/web/handler/GlobalExceptionHandler.java +++ b/intc-common/intc-common-web/src/main/java/com/intc/common/web/handler/GlobalExceptionHandler.java @@ -28,6 +28,7 @@ import org.springframework.web.method.annotation.MethodArgumentTypeMismatchExcep import org.springframework.web.servlet.NoHandlerFoundException; import java.io.IOException; +import java.lang.reflect.InvocationTargetException; /** * 全局异常处理器 @@ -140,6 +141,41 @@ public class GlobalExceptionHandler { public void handleRuntimeException(AsyncRequestTimeoutException e) { } + /** + * 反射调用异常(InvocationTargetException) + * 解包获取真正的异常原因 + */ + @ExceptionHandler(InvocationTargetException.class) + public R handleInvocationTargetException(InvocationTargetException e, HttpServletRequest request) { + String requestURI = request.getRequestURI(); + Throwable targetException = e.getTargetException(); + if (targetException != null) { + log.error("请求地址'{}',反射调用发生异常: {}", requestURI, targetException.getMessage(), targetException); + return R.fail(targetException.getMessage()); + } + log.error("请求地址'{}',反射调用发生未知异常.", requestURI, e); + return R.fail("系统内部错误,请联系管理员"); + } + + /** + * InternalError 异常处理 + * 通常由底层JVM错误或反射调用错误引起 + */ + @ExceptionHandler(InternalError.class) + public R handleInternalError(InternalError e, HttpServletRequest request) { + String requestURI = request.getRequestURI(); + Throwable cause = e.getCause(); + if (cause instanceof InvocationTargetException) { + Throwable targetException = ((InvocationTargetException) cause).getTargetException(); + if (targetException != null) { + log.error("请求地址'{}',发生系统内部错误(InvocationTargetException): {}", requestURI, targetException.getMessage(), targetException); + return R.fail(targetException.getMessage()); + } + } + log.error("请求地址'{}',发生系统内部错误: {}", requestURI, e.getMessage(), e); + return R.fail("系统内部错误: " + (e.getMessage() != null ? e.getMessage() : "请联系管理员")); + } + /** * 拦截未知的运行时异常 */