|
@@ -1,5 +1,6 @@
|
|
|
package com.sckw.gateway.utils;
|
|
package com.sckw.gateway.utils;
|
|
|
|
|
|
|
|
|
|
+import com.sckw.core.exception.BusinessPlatfromException;
|
|
|
import com.sckw.gateway.pojo.HttpResult;
|
|
import com.sckw.gateway.pojo.HttpResult;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.http.server.reactive.ServerHttpRequest;
|
|
import org.springframework.http.server.reactive.ServerHttpRequest;
|
|
@@ -20,6 +21,11 @@ public class GatewayExceptionUtil {
|
|
|
|
|
|
|
|
log.error("网关服务不可用异常: 路径={}, 方法={}, 异常信息={}", path, method, throwable.getMessage());
|
|
log.error("网关服务不可用异常: 路径={}, 方法={}, 异常信息={}", path, method, throwable.getMessage());
|
|
|
|
|
|
|
|
|
|
+ // 【新增】:如果是业务异常,直接提取里面的 code 和 message 透传给前端
|
|
|
|
|
+ if (throwable instanceof BusinessPlatfromException) {
|
|
|
|
|
+ BusinessPlatfromException bizEx = (BusinessPlatfromException) throwable;
|
|
|
|
|
+ return HttpResult.error(bizEx.getErrorCode(), bizEx.getErrorMsg());
|
|
|
|
|
+ }
|
|
|
// 根据异常类型返回不同的错误信息
|
|
// 根据异常类型返回不同的错误信息
|
|
|
if (throwable instanceof org.springframework.cloud.gateway.support.NotFoundException) {
|
|
if (throwable instanceof org.springframework.cloud.gateway.support.NotFoundException) {
|
|
|
return HttpResult.error(60500, "目标服务不存在或未启动");
|
|
return HttpResult.error(60500, "目标服务不存在或未启动");
|