feat: bug-524 调整异常提示,只提示系统错误和编号,不提示具体错误描述
This commit is contained in:
parent
8e1ab13d59
commit
b13c88946a
|
|
@ -131,5 +131,8 @@ public class Constant {
|
|||
public static final String DICTIONARY_PRODUCT_MODEL_MAIN_PARAMS ="ProductModelMainParams";
|
||||
|
||||
public static final String DICTIONARY_PRODUCT_INTRO_CATEGORY ="ProductIntroCategory";
|
||||
|
||||
public static final String DICTIONARY_PRODUCT_MODULE = "ProductModule";
|
||||
|
||||
public static final String TRACE_ID = "traceId";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,10 +2,12 @@ package com.nflg.mobilebroken.starter.advice;
|
|||
|
||||
import cn.dev33.satoken.exception.NotLoginException;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.nflg.mobilebroken.common.constant.Constant;
|
||||
import com.nflg.mobilebroken.common.constant.STATE;
|
||||
import com.nflg.mobilebroken.common.exception.NflgException;
|
||||
import com.nflg.mobilebroken.common.pojo.ApiResult;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.slf4j.MDC;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.validation.FieldError;
|
||||
|
|
@ -28,13 +30,13 @@ public class GlobalRestControllerAdvice {
|
|||
@ExceptionHandler(SQLException.class)
|
||||
public ApiResult<Void> handleSQLException(SQLException ex) {
|
||||
log.error("数据库错误: ", ex);
|
||||
return ApiResult.error(STATE.BusinessError,"数据库错误");
|
||||
return ApiResult.error(STATE.BusinessError, "数据库错误,编号:" + MDC.get(Constant.TRACE_ID));
|
||||
}
|
||||
|
||||
@ExceptionHandler(Exception.class)
|
||||
public ApiResult<Void> handleAllExceptions(Exception ex) {
|
||||
log.error("服务器内部错误: ", ex);
|
||||
return ApiResult.error(STATE.BusinessError,"服务器内部错误: " + ex.getMessage());
|
||||
return ApiResult.error(STATE.BusinessError, "服务器内部错误,编号:" + MDC.get(Constant.TRACE_ID));
|
||||
}
|
||||
|
||||
@ExceptionHandler(NflgException.class)
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package com.nflg.mobilebroken.starter.filter;
|
|||
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.nflg.mobilebroken.common.constant.Constant;
|
||||
import com.nflg.mobilebroken.common.util.AdminUserUtil;
|
||||
import com.nflg.mobilebroken.common.util.AppUserUtil;
|
||||
import com.nflg.mobilebroken.common.util.SaTokenAdminUtil;
|
||||
|
|
@ -29,7 +30,6 @@ import java.util.List;
|
|||
public class TraceIdFilter extends OncePerRequestFilter {
|
||||
|
||||
private static final String TRACE_ID_HEADER = "X-Trace-Id";
|
||||
private static final String MDC_TRACE_ID = "traceId";
|
||||
|
||||
// 需要跳过的二进制内容类型
|
||||
private static final List<String> BINARY_CONTENT_TYPES = Arrays.asList("image", "video", "audio", "stream", "pdf", "zip", "excel");
|
||||
|
|
@ -46,7 +46,7 @@ public class TraceIdFilter extends OncePerRequestFilter {
|
|||
traceId = IdUtil.getSnowflakeNextIdStr();
|
||||
}
|
||||
// 存入MDC和响应头
|
||||
MDC.put(MDC_TRACE_ID, traceId);
|
||||
MDC.put(Constant.TRACE_ID, traceId);
|
||||
responseWrapper.addHeader(TRACE_ID_HEADER, traceId);
|
||||
|
||||
filterChain.doFilter(requestWrapper, responseWrapper);
|
||||
|
|
@ -56,7 +56,7 @@ public class TraceIdFilter extends OncePerRequestFilter {
|
|||
responseWrapper.copyBodyToResponse();
|
||||
|
||||
// 请求结束时清除MDC
|
||||
MDC.remove(MDC_TRACE_ID);
|
||||
MDC.remove(Constant.TRACE_ID);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue