pull/5/MERGE
tanghc 4 years ago
parent 5e906bc4ba
commit 3cef44dc96
  1. 2
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/bean/SopConstants.java
  2. 5
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/handler/GatewayExceptionHandler.java
  3. 7
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/route/GatewayForwardChooser.java

@ -56,4 +56,6 @@ public class SopConstants {
public static final String METADATA_KEY_TIME_STARTUP = "server.startup-time"; public static final String METADATA_KEY_TIME_STARTUP = "server.startup-time";
public static final String CACHE_ROUTE_INFO = "cacheRouteInfo";
} }

@ -1,6 +1,8 @@
package com.gitee.sop.gatewaycommon.gateway.handler; package com.gitee.sop.gatewaycommon.gateway.handler;
import com.gitee.sop.gatewaycommon.bean.ApiContext; 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.gateway.ServerWebExchangeUtil;
import com.gitee.sop.gatewaycommon.param.ApiParam; import com.gitee.sop.gatewaycommon.param.ApiParam;
import com.gitee.sop.gatewaycommon.result.ResultExecutor; import com.gitee.sop.gatewaycommon.result.ResultExecutor;
@ -55,7 +57,8 @@ public class GatewayExceptionHandler implements ErrorWebExceptionHandler {
String errorResult = resultExecutor.buildErrorResult(exchange, ex); String errorResult = resultExecutor.buildErrorResult(exchange, ex);
ApiParam apiParam = ServerWebExchangeUtil.getApiParam(exchange); 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 // 参考AbstractErrorWebExceptionHandler
if (exchange.getResponse().isCommitted()) { if (exchange.getResponse().isCommitted()) {
return Mono.error(ex); return Mono.error(ex);

@ -1,5 +1,7 @@
package com.gitee.sop.gatewaycommon.gateway.route; 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.gateway.ServerWebExchangeUtil;
import com.gitee.sop.gatewaycommon.param.ApiParam; import com.gitee.sop.gatewaycommon.param.ApiParam;
import com.gitee.sop.gatewaycommon.route.BaseForwardChooser; import com.gitee.sop.gatewaycommon.route.BaseForwardChooser;
@ -22,6 +24,9 @@ public class GatewayForwardChooser extends BaseForwardChooser<ServerWebExchange>
if (ServerWebExchangeUtil.getThrowable(exchange) != null) { if (ServerWebExchangeUtil.getThrowable(exchange) != null) {
return ForwardInfo.getErrorForwardInfo(); 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;
} }
} }

Loading…
Cancel
Save