异常处理增强
This commit is contained in:
@@ -242,7 +242,13 @@ public class LogBus implements BaseParams {
|
|||||||
if (log instanceof JSONObject jsonLog) {
|
if (log instanceof JSONObject jsonLog) {
|
||||||
logBody.setLogData(jsonLog);
|
logBody.setLogData(jsonLog);
|
||||||
} else {
|
} else {
|
||||||
logBody.setLogData(JSONObject.from(log));
|
JSONObject logData;
|
||||||
|
try {
|
||||||
|
logData = JSONObject.from(log);
|
||||||
|
} catch (Exception e) {
|
||||||
|
logData = JSONObject.of("data", log);
|
||||||
|
}
|
||||||
|
logBody.setLogData(logData);
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package xtools.boot.web.base.filter;
|
package xtools.boot.web.base.filter;
|
||||||
|
|
||||||
import com.alibaba.fastjson2.JSONObject;
|
|
||||||
import jakarta.servlet.FilterChain;
|
import jakarta.servlet.FilterChain;
|
||||||
import jakarta.servlet.ServletException;
|
import jakarta.servlet.ServletException;
|
||||||
import jakarta.servlet.http.HttpServletRequest;
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
@@ -10,11 +9,8 @@ import org.jspecify.annotations.NonNull;
|
|||||||
import org.springframework.core.Ordered;
|
import org.springframework.core.Ordered;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import xtools.base.config.BaseParams;
|
import xtools.base.config.BaseParams;
|
||||||
import xtools.boot.api.enums.ResultType;
|
|
||||||
import xtools.boot.api.model.dto.Result;
|
|
||||||
import xtools.boot.core.holder.CommonHolder;
|
import xtools.boot.core.holder.CommonHolder;
|
||||||
import xtools.boot.web.filter.base.BaseFilter;
|
import xtools.boot.web.filter.base.BaseFilter;
|
||||||
import xtools.web.HttpServletUtils;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
@@ -48,7 +44,7 @@ public class CommonFilter extends BaseFilter implements Ordered, BaseParams {
|
|||||||
try {
|
try {
|
||||||
filterChain.doFilter(request, response);
|
filterChain.doFilter(request, response);
|
||||||
} catch (IOException | ServletException e) {
|
} catch (IOException | ServletException e) {
|
||||||
log.error("添加通用ScopedValue异常", e);
|
printLog(e, "添加通用ScopedValue异常");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package xtools.boot.web.base.filter;
|
package xtools.boot.web.base.filter;
|
||||||
|
|
||||||
import com.alibaba.fastjson2.JSONObject;
|
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
import jakarta.servlet.FilterChain;
|
import jakarta.servlet.FilterChain;
|
||||||
import jakarta.servlet.ServletException;
|
import jakarta.servlet.ServletException;
|
||||||
@@ -12,8 +11,6 @@ import org.springframework.core.Ordered;
|
|||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import xtools.base.config.BaseParams;
|
import xtools.base.config.BaseParams;
|
||||||
import xtools.boot.api.constant.BootCommonConstant;
|
import xtools.boot.api.constant.BootCommonConstant;
|
||||||
import xtools.boot.api.enums.ResultType;
|
|
||||||
import xtools.boot.api.model.dto.Result;
|
|
||||||
import xtools.boot.api.model.dto.log.HolderLogTrack;
|
import xtools.boot.api.model.dto.log.HolderLogTrack;
|
||||||
import xtools.boot.core.utils.PathPatternUtils;
|
import xtools.boot.core.utils.PathPatternUtils;
|
||||||
import xtools.boot.log.holder.LogTrackHolder;
|
import xtools.boot.log.holder.LogTrackHolder;
|
||||||
@@ -21,7 +18,6 @@ import xtools.boot.web.base.config.LogTrackConfig;
|
|||||||
import xtools.boot.web.filter.base.BaseFilter;
|
import xtools.boot.web.filter.base.BaseFilter;
|
||||||
import xtools.core.StringUtils;
|
import xtools.core.StringUtils;
|
||||||
import xtools.web.HeaderUtils;
|
import xtools.web.HeaderUtils;
|
||||||
import xtools.web.HttpServletUtils;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
@@ -70,7 +66,7 @@ public class LogTrackFilter extends BaseFilter implements Ordered, BaseParams {
|
|||||||
try {
|
try {
|
||||||
filterChain.doFilter(request, response);
|
filterChain.doFilter(request, response);
|
||||||
} catch (IOException | ServletException e) {
|
} catch (IOException | ServletException e) {
|
||||||
log.error("添加日志追踪ScopedValue异常", e);
|
printLog(e, "添加日志追踪ScopedValue异常");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package xtools.boot.web.filter.base;
|
package xtools.boot.web.filter.base;
|
||||||
|
|
||||||
import jakarta.servlet.http.HttpServletRequest;
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.catalina.connector.ClientAbortException;
|
||||||
import org.jspecify.annotations.NonNull;
|
import org.jspecify.annotations.NonNull;
|
||||||
import org.springframework.web.filter.OncePerRequestFilter;
|
import org.springframework.web.filter.OncePerRequestFilter;
|
||||||
|
|
||||||
@@ -15,6 +17,7 @@ import org.springframework.web.filter.OncePerRequestFilter;
|
|||||||
* @version : 5.0.0
|
* @version : 5.0.0
|
||||||
* @date : 2026/3/8 11:06
|
* @date : 2026/3/8 11:06
|
||||||
*/
|
*/
|
||||||
|
@Slf4j
|
||||||
public abstract class BaseFilter extends OncePerRequestFilter {
|
public abstract class BaseFilter extends OncePerRequestFilter {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -31,6 +34,19 @@ public abstract class BaseFilter extends OncePerRequestFilter {
|
|||||||
request.setAttribute(SKIP_FILTER, true);
|
request.setAttribute(SKIP_FILTER, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 日志
|
||||||
|
*
|
||||||
|
* @param e 异常
|
||||||
|
* @param msg 消息
|
||||||
|
*/
|
||||||
|
public void printLog(Exception e, String msg) {
|
||||||
|
if (e instanceof ClientAbortException) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
log.error(msg, e);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 跳过过滤器
|
* 跳过过滤器
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user