seata 异常 日志
This commit is contained in:
@@ -34,6 +34,17 @@ public class CzgControllerAdvice {
|
|||||||
@ExceptionHandler(value = Exception.class)
|
@ExceptionHandler(value = Exception.class)
|
||||||
@ResponseStatus(HttpStatus.OK)
|
@ResponseStatus(HttpStatus.OK)
|
||||||
public CzgResult<Object> errorHandler(Exception ex) {
|
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);
|
setErrorLog(ex);
|
||||||
return CzgResult.failure(CzgRespCode.SYSTEM_ERROR.getCode(), ex.getMessage());
|
return CzgResult.failure(CzgRespCode.SYSTEM_ERROR.getCode(), ex.getMessage());
|
||||||
}
|
}
|
||||||
@@ -143,7 +154,7 @@ public class CzgControllerAdvice {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void setErrorLog(Exception ex) {
|
private void setErrorLog(Exception ex) {
|
||||||
log.error("错误",ex);
|
|
||||||
log.error(ex.getMessage());
|
log.error(ex.getMessage());
|
||||||
|
log.error("错误",ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user