Explorar el Código

feat(proxy): enhance error handling for FastAPI/Pydantic validation errors

Added compatibility for FastAPI/Pydantic validation error format, allowing the extraction of error messages from the "detail" array structure. This improves the robustness of error reporting for specific vendor responses.
ding113 hace 3 meses
padre
commit
bf4b89d16d
Se han modificado 1 ficheros con 12 adiciones y 0 borrados
  1. 12 0
      src/app/v1/_lib/proxy/errors.ts

+ 12 - 0
src/app/v1/_lib/proxy/errors.ts

@@ -231,6 +231,18 @@ export function isNonRetryableClientError(error: Error): boolean {
         message = errorObj.message;
         message = errorObj.message;
       }
       }
     }
     }
+    // 兼容智谱等供应商的 FastAPI/Pydantic 验证错误格式:{ "detail": [{ "msg": "..." }] }
+    if (Array.isArray(parsed.detail)) {
+      for (const item of parsed.detail) {
+        if (item && typeof item === "object") {
+          const detailObj = item as Record<string, unknown>;
+          if (typeof detailObj.msg === "string") {
+            message = detailObj.msg;
+            break;
+          }
+        }
+      }
+    }
   }
   }
 
 
   // 使用预编译正则数组进行匹配,短路优化(第一个匹配成功立即返回)
   // 使用预编译正则数组进行匹配,短路优化(第一个匹配成功立即返回)