浏览代码

fix:修复日志记录的hasException字段没有值的问题

wangzaijun 7 月之前
父节点
当前提交
0634e88903
共有 1 个文件被更改,包括 4 次插入2 次删除
  1. 4 2
      service-deploy/src/main/java/com/simuwang/deploy/components/LoggingAspect.java

+ 4 - 2
service-deploy/src/main/java/com/simuwang/deploy/components/LoggingAspect.java

@@ -36,7 +36,7 @@ public class LoggingAspect {
     }
     }
 
 
     @Around("@annotation(annotation)")
     @Around("@annotation(annotation)")
-    public Object around(ProceedingJoinPoint joinPoint, SystemLog annotation) {
+    public Object around(ProceedingJoinPoint joinPoint, SystemLog annotation) throws Throwable {
         Class<?> clazz = AopUtils.getTargetClass(joinPoint.getTarget());
         Class<?> clazz = AopUtils.getTargetClass(joinPoint.getTarget());
         SystemLog systemLog = clazz.getAnnotation(SystemLog.class);
         SystemLog systemLog = clazz.getAnnotation(SystemLog.class);
         String title = annotation.value();
         String title = annotation.value();
@@ -49,7 +49,7 @@ public class LoggingAspect {
                 .params(joinPoint.getArgs() == null ? Objects.toString(request.getParameterMap()) : JSONUtil.toJsonStr(joinPoint.getArgs()));
                 .params(joinPoint.getArgs() == null ? Objects.toString(request.getParameterMap()) : JSONUtil.toJsonStr(joinPoint.getArgs()));
         StopWatch watch = new StopWatch();
         StopWatch watch = new StopWatch();
         watch.start();
         watch.start();
-        Object result = null;
+        Object result;
         try {
         try {
             result = joinPoint.proceed();
             result = joinPoint.proceed();
             if (annotation.saveResult()) {
             if (annotation.saveResult()) {
@@ -57,6 +57,8 @@ public class LoggingAspect {
             }
             }
         } catch (Throwable throwable) {
         } catch (Throwable throwable) {
             builder.exception(ExceptionUtil.stacktraceToString(throwable));
             builder.exception(ExceptionUtil.stacktraceToString(throwable));
+            builder.hasException(true);
+            throw throwable;
         } finally {
         } finally {
             watch.stop();
             watch.stop();
             builder.executeTime(watch.getTotalTimeMillis());
             builder.executeTime(watch.getTotalTimeMillis());