donglang 13 часов назад
Родитель
Сommit
6367385d37

+ 6 - 0
sckw-gateway/src/main/java/com/sckw/gateway/utils/GatewayExceptionUtil.java

@@ -1,5 +1,6 @@
 package com.sckw.gateway.utils;
 
+import com.sckw.core.exception.BusinessPlatfromException;
 import com.sckw.gateway.pojo.HttpResult;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.http.server.reactive.ServerHttpRequest;
@@ -20,6 +21,11 @@ public class GatewayExceptionUtil {
 
         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) {
             return HttpResult.error(60500, "目标服务不存在或未启动");