From 351d54579e7dfd453f758a5ec7d38e3fd23ca93f Mon Sep 17 00:00:00 2001 From: wangw <1594593906@qq.com> Date: Wed, 12 Nov 2025 11:39:54 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BC=82=E5=B8=B8=E6=89=93=E5=8D=B07?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../czg/exception/CzgControllerAdvice.java | 60 ++++++++++--------- 1 file changed, 31 insertions(+), 29 deletions(-) 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 79c907bcc..af82fa639 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 @@ -144,35 +144,37 @@ public class CzgControllerAdvice { @ExceptionHandler(value = Exception.class) @ResponseStatus(HttpStatus.OK) public CzgResult errorHandler(Exception ex) { -// Throwable rootCause = ex; -// while (rootCause.getCause() != null) { -// rootCause = rootCause.getCause(); -// if (rootCause instanceof CzgException czgException) { -// return CzgResult.failure(czgException.getCode(), czgException.getMessage()); -// } -// if (rootCause instanceof OrderValidateException orderValidateException) { -// return CzgResult.failure(orderValidateException.getCode(), orderValidateException.getMessage()); -// } -// if (rootCause instanceof PaySuccessException) { -// return CzgResult.failure(701, "订单已过期,请重新下单"); -// } -// if (rootCause instanceof OrderCancelException) { -// return CzgResult.success("支付成功"); -// } -// } -// // 处理自定义异常 -// if (rootCause instanceof CzgException czgException) { -// return CzgResult.failure(czgException.getCode(), czgException.getMessage()); -// } -// if (rootCause instanceof OrderValidateException orderValidateException) { -// return CzgResult.failure(orderValidateException.getCode(), orderValidateException.getMessage()); -// } -// if (rootCause instanceof OrderCancelException) { -// return CzgResult.failure(701, "订单已过期,请重新下单"); -// } -// if (rootCause instanceof PaySuccessException) { -// return CzgResult.success("支付成功"); -// } + Throwable rootCause = ex; + log.info("rootCause2:{}", rootCause); + // 处理自定义异常 + if (rootCause instanceof CzgException czgException) { + return CzgResult.failure(czgException.getCode(), czgException.getMessage()); + } + if (rootCause instanceof OrderValidateException orderValidateException) { + return CzgResult.failure(orderValidateException.getCode(), orderValidateException.getMessage()); + } + if (rootCause instanceof OrderCancelException) { + return CzgResult.failure(701, "订单已过期,请重新下单"); + } + if (rootCause instanceof PaySuccessException) { + return CzgResult.success("支付成功"); + } + while (rootCause.getCause() != null) { + log.info("rootCause1:{}", rootCause); + rootCause = rootCause.getCause(); + if (rootCause instanceof CzgException czgException) { + return CzgResult.failure(czgException.getCode(), czgException.getMessage()); + } + if (rootCause instanceof OrderValidateException orderValidateException) { + return CzgResult.failure(orderValidateException.getCode(), orderValidateException.getMessage()); + } + if (rootCause instanceof PaySuccessException) { + return CzgResult.failure(701, "订单已过期,请重新下单"); + } + if (rootCause instanceof OrderCancelException) { + return CzgResult.success("支付成功"); + } + } setErrorLog(ex); return CzgResult.failure(CzgRespCode.SYSTEM_ERROR.getCode(), ex.getMessage()); }