Skip to content

Commit

Permalink
fix(platform): search valid token logic
Browse files Browse the repository at this point in the history
  • Loading branch information
StellarisW committed Dec 17, 2023
1 parent a7e3f61 commit 3601cd6
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
3 changes: 3 additions & 0 deletions platform/server/shared/consts/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ const (
ErrNumCommonGenerateCode
ErrNumCommonProcessFolders
ErrNumCommonMkdir
ErrNumCommonRepoApiService
)

const (
Expand All @@ -208,6 +209,7 @@ const (
ErrMsgCommonGenerateCode = "generate code failed"
ErrMsgCommonProcessFolders = "process folders failed"
ErrMsgCommonMkdir = "mkdir failed"
ErrMsgCommonRepoApiService = "repo api service is down"
)

var (
Expand All @@ -216,4 +218,5 @@ var (
ErrCommonGenerateCode = errx.New(ErrNumCommonGenerateCode, ErrMsgCommonGenerateCode)
ErrCommonProcessFolders = errx.New(ErrNumCommonProcessFolders, ErrMsgCommonProcessFolders)
ErrCommonMkdir = errx.New(ErrNumCommonMkdir, ErrMsgCommonMkdir)
ErrCommonRepoApiService = errx.New(ErrNumCommonRepoApiService, ErrMsgCommonRepoApiService)
)
6 changes: 6 additions & 0 deletions platform/server/shared/repository/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,13 @@ func (rm *Manager) AddClient(repositoryModel *model.Repository) (err error) {
repositoryModel.RepositoryBranch,
)
if err != nil {
if errx.GetCode(err) != consts.ErrNumTokenInvalid {
return err
}
repositoryClient = nil
} else {
repositoryModel.TokenId = tokenModel.Id
break
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions platform/server/shared/utils/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ func GetGitLabTokenInfo(client *gitlab.Client) (owner string, ownerId int64, tok
if strings.Contains(err.Error(), "401 Unauthorized") {
return "", 0, 0, time.Time{}, consts.ErrTokenInvalid
}
if strings.Contains(err.Error(), "404 page not found") {
return "", 0, 0, time.Time{}, consts.ErrCommonRepoApiService
}

return "", 0, 0, time.Time{}, err
}
Expand Down

0 comments on commit 3601cd6

Please sign in to comment.