浏览代码

fix: confused error message if plugin is already installed

Yeuoly 8 月之前
父节点
当前提交
1f1974ec85
共有 3 个文件被更改,包括 13 次插入2 次删除
  1. 5 1
      internal/service/install_plugin.go
  2. 1 1
      internal/types/models/curd/atomic.go
  3. 7 0
      internal/types/models/curd/errors.go

+ 5 - 1
internal/service/install_plugin.go

@@ -319,8 +319,12 @@ func InstallPluginFromIdentifiers(
 				meta,
 			)
 			return err
-		})
+		},
+	)
 	if err != nil {
+		if errors.Is(err, curd.ErrPluginAlreadyInstalled) {
+			return exception.BadRequestError(err).ToResponse()
+		}
 		return exception.InternalServerError(err).ToResponse()
 	}
 

+ 1 - 1
internal/types/models/curd/atomic.go

@@ -34,7 +34,7 @@ func InstallPlugin(
 	)
 
 	if err == nil {
-		return nil, nil, errors.New("plugin already installed")
+		return nil, nil, ErrPluginAlreadyInstalled
 	}
 
 	err = db.WithTransaction(func(tx *gorm.DB) error {

+ 7 - 0
internal/types/models/curd/errors.go

@@ -0,0 +1,7 @@
+package curd
+
+import "errors"
+
+var (
+	ErrPluginAlreadyInstalled = errors.New("plugin already installed")
+)