diff --git a/models/error.go b/models/error.go index 801a91f8b..08548c7da 100644 --- a/models/error.go +++ b/models/error.go @@ -93,19 +93,6 @@ func (err ErrUserHasOrgs) Error() string { return fmt.Sprintf("user still has membership of organizations [uid: %d]", err.UID) } -type ErrReachLimitOfRepo struct { - Limit int -} - -func IsErrReachLimitOfRepo(err error) bool { - _, ok := err.(ErrReachLimitOfRepo) - return ok -} - -func (err ErrReachLimitOfRepo) Error() string { - return fmt.Sprintf("user has reached maximum limit of repositories [limit: %d]", err.Limit) -} - // __ __.__ __ .__ // / \ / \__| | _|__| // \ \/\/ / | |/ / | diff --git a/models/errors/repo.go b/models/errors/repo.go index 1995a5b47..15adb2b05 100644 --- a/models/errors/repo.go +++ b/models/errors/repo.go @@ -21,6 +21,19 @@ func (err RepoNotExist) Error() string { return fmt.Sprintf("repository does not exist [id: %d, user_id: %d, name: %s]", err.ID, err.UserID, err.Name) } +type ReachLimitOfRepo struct { + Limit int +} + +func IsReachLimitOfRepo(err error) bool { + _, ok := err.(ReachLimitOfRepo) + return ok +} + +func (err ReachLimitOfRepo) Error() string { + return fmt.Sprintf("user has reached maximum limit of repositories [limit: %d]", err.Limit) +} + type InvalidRepoReference struct { Ref string } diff --git a/models/repo.go b/models/repo.go index 476a78684..4741bdd6b 100644 --- a/models/repo.go +++ b/models/repo.go @@ -1019,7 +1019,7 @@ func createRepository(e *xorm.Session, doer, owner *User, repo *Repository) (err // CreateRepository creates a repository for given user or organization. func CreateRepository(doer, owner *User, opts CreateRepoOptions) (_ *Repository, err error) { if !owner.CanCreateRepo() { - return nil, ErrReachLimitOfRepo{owner.MaxRepoCreation} + return nil, errors.ReachLimitOfRepo{owner.RepoCreationNum()} } repo := &Repository{ diff --git a/models/user.go b/models/user.go index 79774ae8e..642499719 100644 --- a/models/user.go +++ b/models/user.go @@ -610,8 +610,9 @@ func getVerifyUser(code string) (user *User) { if b, err := hex.DecodeString(hexStr); err == nil { if user, err = GetUserByName(string(b)); user != nil { return user + } else if !errors.IsUserNotExist(err) { + log.Error(2, "GetUserByName: %v", err) } - log.Error(4, "user.getVerifyUser: %v", err) } return nil diff --git a/routers/api/v1/repo/repo.go b/routers/api/v1/repo/repo.go index fdb3e7a59..f86905d49 100644 --- a/routers/api/v1/repo/repo.go +++ b/routers/api/v1/repo/repo.go @@ -250,7 +250,7 @@ func Migrate(ctx *context.APIContext, f form.MigrateRepo) { case addrErr.IsPermissionDenied: ctx.Error(422, "", "You are not allowed to import local repositories") case addrErr.IsInvalidPath: - ctx.Error(422, "", "Invalid local path, it does not exist or not a directory.") + ctx.Error(422, "", "Invalid local path, it does not exist or not a directory") default: ctx.Error(500, "ParseRemoteAddr", "Unknown error type (ErrInvalidCloneAddr): "+err.Error()) } @@ -273,7 +273,12 @@ func Migrate(ctx *context.APIContext, f form.MigrateRepo) { log.Error(2, "DeleteRepository: %v", errDelete) } } - ctx.Error(500, "MigrateRepository", models.HandleMirrorCredentials(err.Error(), true)) + + if errors.IsReachLimitOfRepo(err) { + ctx.Error(422, "", err) + } else { + ctx.Error(500, "MigrateRepository", models.HandleMirrorCredentials(err.Error(), true)) + } return } diff --git a/routers/repo/repo.go b/routers/repo/repo.go index 3f99f53c0..a50fc937d 100644 --- a/routers/repo/repo.go +++ b/routers/repo/repo.go @@ -87,7 +87,7 @@ func Create(ctx *context.Context) { func handleCreateError(ctx *context.Context, owner *models.User, err error, name, tpl string, form interface{}) { switch { - case models.IsErrReachLimitOfRepo(err): + case errors.IsReachLimitOfRepo(err): ctx.RenderWithErr(ctx.Tr("repo.form.reach_limit_of_creation", owner.RepoCreationNum()), tpl, form) case models.IsErrRepoAlreadyExist(err): ctx.Data["Err_RepoName"] = true