Skip to content

Commit 019bd02

Browse files
QinYuuuuDev Agent
andauthored
Fix collection message (#674)
Co-authored-by: Dev Agent <[email protected]>
1 parent 66ee50b commit 019bd02

File tree

5 files changed

+56
-1
lines changed

5 files changed

+56
-1
lines changed

common/errorx/error_collection.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package errorx
2+
3+
const errCollectionPrefix = "COLL-ERR"
4+
5+
const (
6+
repoAlreadyInCollection = iota
7+
)
8+
9+
var (
10+
// the repository is already in the collection
11+
//
12+
// Description: The repository you are trying to add is already present in this collection.
13+
//
14+
// Description_ZH: 您尝试添加的仓库已经在此集合中。
15+
//
16+
// en-US: The repo was already in this collection
17+
//
18+
// zh-CN: 该仓库已经在此集合中
19+
//
20+
// zh-HK: 該倉庫已經在此集合中
21+
ErrRepoAlreadyInCollection error = CustomError{prefix: errCollectionPrefix, code: repoAlreadyInCollection}
22+
)
23+
24+
func RepoAlreadyInCollection(err error, ctx context) error {
25+
if err == nil {
26+
return nil
27+
}
28+
return CustomError{
29+
prefix: errCollectionPrefix,
30+
context: ctx,
31+
err: err,
32+
code: int(repoAlreadyInCollection),
33+
}
34+
}
35+
36+
37+
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"error.COLL-ERR-0": {
3+
"other": "The item was already in this collection"
4+
}
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"error.COLL-ERR-0": {
3+
"other": "项目已经在此集合中"
4+
}
5+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"error.COLL-ERR-0": {
3+
"other": "該倉庫已經在此集合中"
4+
}
5+
}
6+
7+
8+

component/collection.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ func (cc *collectionComponentImpl) AddReposToCollection(ctx context.Context, req
232232
if err != nil {
233233
// Check if the error is a duplicate key constraint violation
234234
if strings.Contains(err.Error(), "duplicate key value") {
235-
return fmt.Errorf("the repo was already in this collection: %s", strconv.FormatInt(req.ID, 10))
235+
return errorx.RepoAlreadyInCollection(err, errorx.Ctx().Set("collection_id", strconv.FormatInt(req.ID, 10)))
236236
}
237237
if strings.Contains(err.Error(), "violates foreign key constraint") {
238238
return fmt.Errorf("repo not found: %v", req.RepoIDs)

0 commit comments

Comments
 (0)