异常打印7

This commit is contained in:
2025-11-12 11:39:54 +08:00
parent 0298c53320
commit 351d54579e

View File

@@ -144,35 +144,37 @@ public class CzgControllerAdvice {
@ExceptionHandler(value = Exception.class)
@ResponseStatus(HttpStatus.OK)
public CzgResult<Object> 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());
}