显式抛出
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -86,7 +86,6 @@ public class CzgControllerAdvice {
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 处理自定义异常
|
||||
*/
|
||||
@@ -164,9 +163,20 @@ public class CzgControllerAdvice {
|
||||
@ExceptionHandler(value = Exception.class)
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
public CzgResult<Object> 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(), "系统错误,请联系管理员");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user