mirror of
https://gitee.com/durcframework/SOP.git
synced 2025-08-12 07:02:14 +08:00
修复监控异常乱码问题. thx for 清风
This commit is contained in:
@@ -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("系统繁忙"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user