diff options
author | Unknwon <u@gogs.io> | 2015-03-26 17:11:47 -0400 |
---|---|---|
committer | Unknwon <u@gogs.io> | 2015-03-26 17:11:47 -0400 |
commit | 698b9e2acc4daafe7d2b314e2d8c96545dde9c40 (patch) | |
tree | 8d593bb0816503494de4deb16ee0fa6b95eb3c5c /routers/repo/repo.go | |
parent | d76f11c6f14b69bf981e5fc3901cc2c6445773b8 (diff) | |
download | gitea-698b9e2acc4daafe7d2b314e2d8c96545dde9c40.tar.gz gitea-698b9e2acc4daafe7d2b314e2d8c96545dde9c40.zip |
#1070 Clearer error message for illegal characters
Diffstat (limited to 'routers/repo/repo.go')
-rw-r--r-- | routers/repo/repo.go | 70 |
1 files changed, 43 insertions, 27 deletions
diff --git a/routers/repo/repo.go b/routers/repo/repo.go index 73c9277d94..5e6a2e0d20 100644 --- a/routers/repo/repo.go +++ b/routers/repo/repo.go @@ -110,14 +110,6 @@ func CreatePost(ctx *middleware.Context, form auth.CreateRepoForm) { log.Trace("Repository created: %s/%s", ctxUser.Name, repo.Name) ctx.Redirect(setting.AppSubUrl + "/" + ctxUser.Name + "/" + repo.Name) return - } else if err == models.ErrRepoAlreadyExist { - ctx.Data["Err_RepoName"] = true - ctx.RenderWithErr(ctx.Tr("form.repo_name_been_taken"), CREATE, &form) - return - } else if err == models.ErrRepoNameIllegal { - ctx.Data["Err_RepoName"] = true - ctx.RenderWithErr(ctx.Tr("form.illegal_repo_name"), CREATE, &form) - return } if repo != nil { @@ -125,7 +117,20 @@ func CreatePost(ctx *middleware.Context, form auth.CreateRepoForm) { log.Error(4, "DeleteRepository: %v", errDelete) } } - ctx.Handle(500, "CreatePost", err) + + switch { + case err == models.ErrRepoAlreadyExist: + ctx.Data["Err_RepoName"] = true + ctx.RenderWithErr(ctx.Tr("form.repo_name_been_taken"), CREATE, &form) + case models.IsErrNameReserved(err): + ctx.Data["Err_RepoName"] = true + ctx.RenderWithErr(ctx.Tr("repo.form.name_reserved", err.(models.ErrNameReserved).Name), CREATE, &form) + case models.IsErrNamePatternNotAllowed(err): + ctx.Data["Err_RepoName"] = true + ctx.RenderWithErr(ctx.Tr("repo.form.name_pattern_not_allowed", err.(models.ErrNamePatternNotAllowed).Pattern), CREATE, &form) + default: + ctx.Handle(500, "CreatePost", err) + } } func Migrate(ctx *middleware.Context) { @@ -209,14 +214,6 @@ func MigratePost(ctx *middleware.Context, form auth.MigrateRepoForm) { log.Trace("Repository migrated: %s/%s", ctxUser.Name, form.RepoName) ctx.Redirect(setting.AppSubUrl + "/" + ctxUser.Name + "/" + form.RepoName) return - } else if err == models.ErrRepoAlreadyExist { - ctx.Data["Err_RepoName"] = true - ctx.RenderWithErr(ctx.Tr("form.repo_name_been_taken"), MIGRATE, &form) - return - } else if err == models.ErrRepoNameIllegal { - ctx.Data["Err_RepoName"] = true - ctx.RenderWithErr(ctx.Tr("form.illegal_repo_name"), MIGRATE, &form) - return } if repo != nil { @@ -230,7 +227,20 @@ func MigratePost(ctx *middleware.Context, form auth.MigrateRepoForm) { ctx.RenderWithErr(ctx.Tr("form.auth_failed", err), MIGRATE, &form) return } - ctx.Handle(500, "MigratePost", err) + + switch { + case err == models.ErrRepoAlreadyExist: + ctx.Data["Err_RepoName"] = true + ctx.RenderWithErr(ctx.Tr("form.repo_name_been_taken"), MIGRATE, &form) + case models.IsErrNameReserved(err): + ctx.Data["Err_RepoName"] = true + ctx.RenderWithErr(ctx.Tr("repo.form.name_reserved", err.(models.ErrNameReserved).Name), MIGRATE, &form) + case models.IsErrNamePatternNotAllowed(err): + ctx.Data["Err_RepoName"] = true + ctx.RenderWithErr(ctx.Tr("repo.form.name_pattern_not_allowed", err.(models.ErrNamePatternNotAllowed).Pattern), MIGRATE, &form) + default: + ctx.Handle(500, "MigratePost", err) + } } func getForkRepository(ctx *middleware.Context) (*models.Repository, error) { @@ -323,14 +333,6 @@ func ForkPost(ctx *middleware.Context, form auth.CreateRepoForm) { log.Trace("Repository forked: %s/%s", ctxUser.Name, repo.Name) ctx.Redirect(setting.AppSubUrl + "/" + ctxUser.Name + "/" + repo.Name) return - } else if err == models.ErrRepoAlreadyExist { - ctx.Data["Err_RepoName"] = true - ctx.RenderWithErr(ctx.Tr("form.repo_name_been_taken"), FORK, &form) - return - } else if err == models.ErrRepoNameIllegal { - ctx.Data["Err_RepoName"] = true - ctx.RenderWithErr(ctx.Tr("form.illegal_repo_name"), CREATE, &form) - return } if repo != nil { @@ -338,7 +340,21 @@ func ForkPost(ctx *middleware.Context, form auth.CreateRepoForm) { log.Error(4, "DeleteRepository: %v", errDelete) } } - ctx.Handle(500, "ForkPost", err) + + // FIXME: merge this with other 2 error handling in to one. + switch { + case err == models.ErrRepoAlreadyExist: + ctx.Data["Err_RepoName"] = true + ctx.RenderWithErr(ctx.Tr("form.repo_name_been_taken"), FORK, &form) + case models.IsErrNameReserved(err): + ctx.Data["Err_RepoName"] = true + ctx.RenderWithErr(ctx.Tr("repo.form.name_reserved", err.(models.ErrNameReserved).Name), FORK, &form) + case models.IsErrNamePatternNotAllowed(err): + ctx.Data["Err_RepoName"] = true + ctx.RenderWithErr(ctx.Tr("repo.form.name_pattern_not_allowed", err.(models.ErrNamePatternNotAllowed).Pattern), FORK, &form) + default: + ctx.Handle(500, "ForkPost", err) + } } func Action(ctx *middleware.Context) { |