diff --git a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/bean/SopConstants.java b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/bean/SopConstants.java index c6d56b4c..7af00f96 100644 --- a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/bean/SopConstants.java +++ b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/bean/SopConstants.java @@ -56,4 +56,6 @@ public class SopConstants { public static final String METADATA_KEY_TIME_STARTUP = "server.startup-time"; + public static final String CACHE_ROUTE_INFO = "cacheRouteInfo"; + } diff --git a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/handler/GatewayExceptionHandler.java b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/handler/GatewayExceptionHandler.java index 0f623358..4c992a9c 100644 --- a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/handler/GatewayExceptionHandler.java +++ b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/handler/GatewayExceptionHandler.java @@ -1,6 +1,8 @@ package com.gitee.sop.gatewaycommon.gateway.handler; import com.gitee.sop.gatewaycommon.bean.ApiContext; +import com.gitee.sop.gatewaycommon.bean.SopConstants; +import com.gitee.sop.gatewaycommon.bean.TargetRoute; import com.gitee.sop.gatewaycommon.gateway.ServerWebExchangeUtil; import com.gitee.sop.gatewaycommon.param.ApiParam; import com.gitee.sop.gatewaycommon.result.ResultExecutor; @@ -55,7 +57,8 @@ public class GatewayExceptionHandler implements ErrorWebExceptionHandler { String errorResult = resultExecutor.buildErrorResult(exchange, ex); ApiParam apiParam = ServerWebExchangeUtil.getApiParam(exchange); // 错误记录 - log.error("gateway网关报错,params:{}, errorMsg:{}", apiParam, ex.getMessage(), ex); + Object routeDefinition = exchange.getAttribute(SopConstants.CACHE_ROUTE_INFO); + log.error("网关报错,参数:{}, 错误信息:{}, 路由信息:{}", apiParam, ex.getMessage(), routeDefinition, ex); // 参考AbstractErrorWebExceptionHandler if (exchange.getResponse().isCommitted()) { return Mono.error(ex); diff --git a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/route/GatewayForwardChooser.java b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/route/GatewayForwardChooser.java index bb9b474d..85ced0da 100644 --- a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/route/GatewayForwardChooser.java +++ b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/route/GatewayForwardChooser.java @@ -1,5 +1,7 @@ package com.gitee.sop.gatewaycommon.gateway.route; +import com.gitee.sop.gatewaycommon.bean.SopConstants; +import com.gitee.sop.gatewaycommon.bean.TargetRoute; import com.gitee.sop.gatewaycommon.gateway.ServerWebExchangeUtil; import com.gitee.sop.gatewaycommon.param.ApiParam; import com.gitee.sop.gatewaycommon.route.BaseForwardChooser; @@ -22,6 +24,9 @@ public class GatewayForwardChooser extends BaseForwardChooser if (ServerWebExchangeUtil.getThrowable(exchange) != null) { return ForwardInfo.getErrorForwardInfo(); } - return super.getForwardInfo(exchange); + ForwardInfo forwardInfo = super.getForwardInfo(exchange); + TargetRoute targetRoute = forwardInfo.getTargetRoute(); + exchange.getAttributes().put(SopConstants.CACHE_ROUTE_INFO, targetRoute.getRouteDefinition()); + return forwardInfo; } }