From b359b08713faeb463a5fd1d278b2b81c71075f19 Mon Sep 17 00:00:00 2001 From: wangw <1594593906@qq.com> Date: Wed, 24 Dec 2025 14:27:35 +0800 Subject: [PATCH] =?UTF-8?q?=E6=98=BE=E5=BC=8F=E6=8A=9B=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/czg/controller/NotifyController.java | 3 +-- .../com/czg/exception/CzgControllerAdvice.java | 16 +++++++++++++--- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/cash-api/order-server/src/main/java/com/czg/controller/NotifyController.java b/cash-api/order-server/src/main/java/com/czg/controller/NotifyController.java index a3657bec8..ad5b51dc0 100644 --- a/cash-api/order-server/src/main/java/com/czg/controller/NotifyController.java +++ b/cash-api/order-server/src/main/java/com/czg/controller/NotifyController.java @@ -4,8 +4,8 @@ import cn.hutool.core.date.DateUtil; import cn.hutool.core.io.IoUtil; import com.alibaba.fastjson2.JSONObject; import com.czg.CzgPayUtils; -import com.czg.account.entity.ShopUser; import com.czg.account.service.ShopUserService; +import com.czg.constants.PayTypeConstants; import com.czg.entity.CzgBaseRespParams; import com.czg.market.entity.MkShopConsumeDiscountRecord; import com.czg.market.service.MkDistributionUserService; @@ -13,7 +13,6 @@ import com.czg.market.service.MkShopConsumeDiscountRecordService; import com.czg.market.service.OrderInfoService; import com.czg.order.entity.OrderInfo; import com.czg.order.entity.OrderPayment; -import com.czg.constants.PayTypeConstants; import com.czg.order.service.OrderInfoCustomService; import com.czg.order.service.OrderPaymentService; import com.czg.service.market.service.impl.AppWxServiceImpl; diff --git a/cash-common/cash-common-api-config/src/main/java/com/czg/exception/CzgControllerAdvice.java b/cash-common/cash-common-api-config/src/main/java/com/czg/exception/CzgControllerAdvice.java index c07d32e2e..b4aeb5569 100644 --- a/cash-common/cash-common-api-config/src/main/java/com/czg/exception/CzgControllerAdvice.java +++ b/cash-common/cash-common-api-config/src/main/java/com/czg/exception/CzgControllerAdvice.java @@ -86,7 +86,6 @@ public class CzgControllerAdvice { } - /** * 处理自定义异常 */ @@ -164,9 +163,20 @@ public class CzgControllerAdvice { @ExceptionHandler(value = Exception.class) @ResponseStatus(HttpStatus.OK) public CzgResult errorHandler(Exception ex) { -// setErrorLog(ex); - // 3. 处理未捕获的异常(系统异常,隐藏敏感信息) log.error("系统未处理异常", ex); + Throwable rootCause = ex; + while (rootCause.getCause() != null && !(rootCause instanceof CzgException)) { + rootCause = rootCause.getCause(); + } + + // 2. 如果根因是CzgException,直接抛出/返回该异常 + if (rootCause instanceof CzgException exception) { + return CzgResult.failure(exception.getCode(), exception.getMsg()); + }else if (rootCause instanceof ValidateException exception) { + return CzgResult.failure(exception.getStatus(), exception.getMessage()); + } + + // 3. 非业务异常,按原有逻辑处理 return CzgResult.failure(CzgRespCode.SYSTEM_ERROR.getCode(), "系统错误,请联系管理员"); }