Explorar o código

fix: wrap marketplace apis with try catch

Yeuoly hai 6 meses
pai
achega
38cae29757
Modificáronse 2 ficheiros con 12 adicións e 2 borrados
  1. 1 1
      api/core/helper/marketplace.py
  2. 11 1
      api/services/plugin/plugin_service.py

+ 1 - 1
api/core/helper/marketplace.py

@@ -24,6 +24,6 @@ def batch_fetch_plugin_manifests(plugin_ids: list[str]) -> Sequence[MarketplaceP
         return []
 
     url = str(URL(str(dify_config.MARKETPLACE_API_URL)) / "api/v1/plugins/batch")
-    response = requests.get(url, json={"plugin_ids": plugin_ids})
+    response = requests.post(url, json={"plugin_ids": plugin_ids})
     response.raise_for_status()
     return [MarketplacePluginDeclaration(**plugin) for plugin in response.json()["plugins"]]

+ 11 - 1
api/services/plugin/plugin_service.py

@@ -1,3 +1,4 @@
+import logging
 from collections.abc import Sequence
 from mimetypes import guess_type
 
@@ -11,6 +12,8 @@ from core.plugin.manager.asset import PluginAssetManager
 from core.plugin.manager.debugging import PluginDebuggingManager
 from core.plugin.manager.plugin import PluginInstallationManager
 
+logger = logging.getLogger(__name__)
+
 
 class PluginService:
     @staticmethod
@@ -29,7 +32,14 @@ class PluginService:
         manager = PluginInstallationManager()
         plugins = manager.list_plugins(tenant_id)
         plugin_ids = [plugin.plugin_id for plugin in plugins if plugin.source == PluginInstallationSource.Marketplace]
-        manifests = {manifest.plugin_id: manifest for manifest in marketplace.batch_fetch_plugin_manifests(plugin_ids)}
+        try:
+            manifests = {
+                manifest.plugin_id: manifest for manifest in marketplace.batch_fetch_plugin_manifests(plugin_ids)
+            }
+        except Exception as e:
+            manifests = {}
+            logger.exception(f"failed to fetch plugin manifests: {e}")
+
         for plugin in plugins:
             if plugin.source == PluginInstallationSource.Marketplace:
                 if plugin.plugin_id in manifests: