额外的异常

This commit is contained in:
2025-11-12 13:30:57 +08:00
parent 8634f1a5a6
commit 89762d0589
3 changed files with 9 additions and 38 deletions

View File

@@ -144,39 +144,10 @@ public class CzgControllerAdvice {
@ExceptionHandler(value = Exception.class)
@ResponseStatus(HttpStatus.OK)
public CzgResult<Object> errorHandler(Exception ex) {
Throwable rootCause = ex;
log.info("rootCause2:{}", rootCause.getClass());
// 处理自定义异常
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.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("支付成功");
}
}
setErrorLog(ex);
return CzgResult.failure(CzgRespCode.SYSTEM_ERROR.getCode(), ex.getMessage());
// setErrorLog(ex);
// 3. 处理未捕获的异常(系统异常,隐藏敏感信息)
log.error("系统未处理异常", ex); // 替换原有 setErrorLog使用日志框架
return CzgResult.failure(CzgRespCode.SYSTEM_ERROR.getCode(), "系统繁忙,请稍后再试");
}
private void setErrorLog(Exception ex) {