会员充值/霸王餐支付 关联id问题

统一异常拦截 rootCause 值
CLIENT_LOGIC 与 USER_LOGIC 问题
This commit is contained in:
2026-01-21 10:17:09 +08:00
parent 45965fb426
commit 0549a077b2
11 changed files with 73 additions and 65 deletions

View File

@@ -8,6 +8,7 @@ import com.czg.resp.CzgRespCode;
import com.czg.resp.CzgResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.support.DefaultMessageSourceResolvable;
import org.springframework.core.NestedExceptionUtils;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.http.HttpStatus;
import org.springframework.http.converter.HttpMessageNotReadableException;
@@ -164,20 +165,23 @@ public class CzgControllerAdvice {
@ResponseStatus(HttpStatus.OK)
public CzgResult<Object> errorHandler(Exception ex) {
log.error("系统未处理异常", ex);
Throwable rootCause = ex;
while (rootCause.getCause() != null && !(rootCause instanceof CzgException)) {
rootCause = rootCause.getCause();
}
String rootMsg = NestedExceptionUtils.getMostSpecificCause(ex).getMessage();
return CzgResult.failure(CzgRespCode.FAILURE.getCode(), rootMsg);
// 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());
}
// 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(), "系统错误,请联系管理员");
// return CzgResult.failure(CzgRespCode.SYSTEM_ERROR.getCode(), "系统错误,请联系管理员");
}
private void setErrorLog(Exception ex) {