Bläddra i källkod

修改执行调用错误后按钮一直转圈问题

zyf 1 månad sedan
förälder
incheckning
5c1fed687e
1 ändrade filer med 17 tillägg och 16 borttagningar
  1. 17 16
      src/components/App.tsx

+ 17 - 16
src/components/App.tsx

@@ -208,31 +208,32 @@ function App() {
     setCallLoading(true);
     setResult('');
     
-    const token = getToken();
-    const userInfo = getUserInfo();
-    
-    const apiItem = {
-      ...currentApi,
-      aiTableId: customTableId || currentApi.aiTableId,
-      aiTablename: tableName,
-      apiParamAuth: currentApi.apiParamAuth.map(p => ({
-        paramName: p.paramName,
-        value: apiParams[p.paramName] || p.value || ''
-      }))
-    };
-    
     try {
+      const token = getToken();
+      const userInfo = getUserInfo();
+      
+      const apiItem = {
+        ...currentApi,
+        aiTableId: customTableId || currentApi.aiTableId,
+        aiTablename: tableName,
+        apiParamAuth: currentApi.apiParamAuth.map(p => ({
+          paramName: p.paramName,
+          value: apiParams[p.paramName] || p.value || ''
+        }))
+      };
+      
       const response: ApiResponse = await Dingdocs.script.runWithTimeout('callApi', 120000, apiItem, token, userInfo?.userId);
-      if (response.code === 200 || response.code === 0) {
+      if (response && (response.code === 200 || response.code === 0)) {
         setResult(JSON.stringify(response, null, 2));
       } else {
-        setResult(`调用失败: ${response.msg || '未知错误'}`);
+        setResult(`调用失败: ${response?.msg || '未知错误'}`);
       }
     } catch (error: any) {
       console.error('调用API失败:', error);
       setResult(`调用失败: ${error?.message || '网络请求超时,请检查网络连接'}`);
+    } finally {
+      setCallLoading(false);
     }
-    setCallLoading(false);
   };
 
   useEffect(() => {