异常打印5

This commit is contained in:
wangw 2025-11-12 11:34:23 +08:00
parent 5141c019cd
commit 4e90ca4362
1 changed files with 29 additions and 30 deletions

View File

@ -144,36 +144,35 @@ public class CzgControllerAdvice {
@ExceptionHandler(value = Exception.class)
@ResponseStatus(HttpStatus.OK)
public CzgResult<Object> errorHandler(Exception ex) {
Throwable rootCause = ex;
while (rootCause.getCause() != null) {
log.info("rootCause:{}", rootCause.getClass());
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;
// 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("支付成功");
// }
setErrorLog(ex);
return CzgResult.failure(CzgRespCode.SYSTEM_ERROR.getCode(), ex.getMessage());
}