修复监控异常乱码问题. thx for 清风

taobao_model
tanghc 5 years ago
parent 801b5f1fd4
commit e0249e5e6e
  1. 6
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/result/GatewayResultExecutor.java
  2. 4
      sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/configuration/GlobalExceptionHandler.java

@ -14,8 +14,11 @@ import com.gitee.sop.gatewaycommon.result.ResultExecutorForGateway;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.server.ServerWebExchange; import org.springframework.web.server.ServerWebExchange;
import org.springframework.web.util.UriUtils;
import java.nio.charset.StandardCharsets;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
@ -46,6 +49,9 @@ public class GatewayResultExecutor extends BaseExecutorAdapter<ServerWebExchange
if (!CollectionUtils.isEmpty(errorMessageList)) { if (!CollectionUtils.isEmpty(errorMessageList)) {
errorMsg = errorMessageList.get(0); errorMsg = errorMessageList.get(0);
} }
if (StringUtils.hasText(errorMsg)) {
errorMsg = UriUtils.decode(errorMsg, StandardCharsets.UTF_8);
}
exchange.getResponse().getHeaders().remove(SopConstants.X_SERVICE_ERROR_MESSAGE); exchange.getResponse().getHeaders().remove(SopConstants.X_SERVICE_ERROR_MESSAGE);
return errorMsg; return errorMsg;
} }

@ -9,9 +9,11 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice; import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.util.UriUtils;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.nio.charset.StandardCharsets;
/** /**
* 全局异常处理 * 全局异常处理
@ -75,7 +77,7 @@ public class GlobalExceptionHandler {
StackTraceElement stackTraceElement = stackTrace[i]; StackTraceElement stackTraceElement = stackTrace[i];
msg.append("<br> at ").append(stackTraceElement.toString()); msg.append("<br> at ").append(stackTraceElement.toString());
} }
response.setHeader("x-service-error-message", msg.toString()); response.setHeader("x-service-error-message", UriUtils.encode(msg.toString(), StandardCharsets.UTF_8));
return this.processError(request, response, new ServiceException("系统繁忙")); return this.processError(request, response, new ServiceException("系统繁忙"));
} }

Loading…
Cancel
Save