浏览代码

fix: optimize error messages

Yeuoly 7 月之前
父节点
当前提交
f9fc134982
共有 2 个文件被更改,包括 12 次插入4 次删除
  1. 3 0
      internal/service/plugin_decoder.go
  2. 9 4
      internal/utils/cache/helper/redis.go

+ 3 - 0
internal/service/plugin_decoder.go

@@ -173,6 +173,9 @@ func FetchPluginManifest(
 	pluginManifestCache, err := helper.CombinedGetPluginDeclaration(
 		pluginUniqueIdentifier, tenant_id, runtimeType,
 	)
+	if err == helper.ErrPluginNotFound {
+		return exception.BadRequestError(errors.New("plugin not found")).ToResponse()
+	}
 
 	if err != nil {
 		return exception.InternalServerError(err).ToResponse()

+ 9 - 4
internal/utils/cache/helper/redis.go

@@ -1,6 +1,7 @@
 package helper
 
 import (
+	"errors"
 	"strings"
 
 	"github.com/langgenius/dify-plugin-daemon/internal/db"
@@ -9,6 +10,10 @@ import (
 	"github.com/langgenius/dify-plugin-daemon/internal/utils/cache"
 )
 
+var (
+	ErrPluginNotFound = errors.New("plugin not found")
+)
+
 func CombinedGetPluginDeclaration(
 	plugin_unique_identifier plugin_entities.PluginUniqueIdentifier,
 	tenant_id string,
@@ -27,8 +32,8 @@ func CombinedGetPluginDeclaration(
 				declaration, err := db.GetOne[models.PluginDeclaration](
 					db.Equal("plugin_unique_identifier", plugin_unique_identifier.String()),
 				)
-				if err != nil && err != db.ErrDatabaseNotFound {
-					return nil, err
+				if err == db.ErrDatabaseNotFound {
+					return nil, ErrPluginNotFound
 				}
 
 				if err != nil {
@@ -42,8 +47,8 @@ func CombinedGetPluginDeclaration(
 					db.Equal("plugin_unique_identifier", plugin_unique_identifier.String()),
 					db.Equal("install_type", string(plugin_entities.PLUGIN_RUNTIME_TYPE_REMOTE)),
 				)
-				if err != nil && err != db.ErrDatabaseNotFound {
-					return nil, err
+				if err == db.ErrDatabaseNotFound {
+					return nil, ErrPluginNotFound
 				}
 
 				if err != nil {