seata 异常 日志

This commit is contained in:
2025-11-05 17:49:31 +08:00
parent ae0e85fb04
commit 033db28c0b

View File

@@ -34,6 +34,17 @@ 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) {
break;
}
}
// 处理自定义异常
if (rootCause instanceof CzgException czgException) {
return CzgResult.failure(czgException.getCode(), czgException.getMessage());
}
setErrorLog(ex);
return CzgResult.failure(CzgRespCode.SYSTEM_ERROR.getCode(), ex.getMessage());
}
@@ -143,7 +154,7 @@ public class CzgControllerAdvice {
}
private void setErrorLog(Exception ex) {
log.error("错误",ex);
log.error(ex.getMessage());
log.error("错误",ex);
}
}