diff options
Diffstat (limited to 'routers')
45 files changed, 558 insertions, 554 deletions
diff --git a/routers/admin/auths.go b/routers/admin/auths.go index 590e45a4f4..3915c618b3 100644 --- a/routers/admin/auths.go +++ b/routers/admin/auths.go @@ -35,7 +35,7 @@ func Authentications(ctx *context.Context) { var err error ctx.Data["Sources"], err = models.LoginSources() if err != nil { - ctx.Handle(500, "LoginSources", err) + ctx.ServerError("LoginSources", err) return } @@ -197,7 +197,7 @@ func NewAuthSourcePost(ctx *context.Context, form auth.AuthenticationForm) { ctx.Data["Err_Name"] = true ctx.RenderWithErr(ctx.Tr("admin.auths.login_source_exist", err.(models.ErrLoginSourceAlreadyExist).Name), tplAuthNew, form) } else { - ctx.Handle(500, "CreateSource", err) + ctx.ServerError("CreateSource", err) } return } @@ -221,7 +221,7 @@ func EditAuthSource(ctx *context.Context) { source, err := models.GetLoginSourceByID(ctx.ParamsInt64(":authid")) if err != nil { - ctx.Handle(500, "GetLoginSourceByID", err) + ctx.ServerError("GetLoginSourceByID", err) return } ctx.Data["Source"] = source @@ -245,7 +245,7 @@ func EditAuthSourcePost(ctx *context.Context, form auth.AuthenticationForm) { source, err := models.GetLoginSourceByID(ctx.ParamsInt64(":authid")) if err != nil { - ctx.Handle(500, "GetLoginSourceByID", err) + ctx.ServerError("GetLoginSourceByID", err) return } ctx.Data["Source"] = source @@ -282,7 +282,7 @@ func EditAuthSourcePost(ctx *context.Context, form auth.AuthenticationForm) { ctx.Flash.Error(err.Error(), true) ctx.HTML(200, tplAuthEdit) } else { - ctx.Handle(500, "UpdateSource", err) + ctx.ServerError("UpdateSource", err) } return } @@ -296,7 +296,7 @@ func EditAuthSourcePost(ctx *context.Context, form auth.AuthenticationForm) { func DeleteAuthSource(ctx *context.Context) { source, err := models.GetLoginSourceByID(ctx.ParamsInt64(":authid")) if err != nil { - ctx.Handle(500, "GetLoginSourceByID", err) + ctx.ServerError("GetLoginSourceByID", err) return } diff --git a/routers/admin/notice.go b/routers/admin/notice.go index 2cf71ee070..5892d88e58 100644 --- a/routers/admin/notice.go +++ b/routers/admin/notice.go @@ -34,7 +34,7 @@ func Notices(ctx *context.Context) { notices, err := models.Notices(page, setting.UI.Admin.NoticePagingNum) if err != nil { - ctx.Handle(500, "Notices", err) + ctx.ServerError("Notices", err) return } ctx.Data["Notices"] = notices @@ -66,7 +66,7 @@ func DeleteNotices(ctx *context.Context) { // EmptyNotices delete all the notices func EmptyNotices(ctx *context.Context) { if err := models.DeleteNotices(0, 0); err != nil { - ctx.Handle(500, "DeleteNotices", err) + ctx.ServerError("DeleteNotices", err) return } diff --git a/routers/admin/repos.go b/routers/admin/repos.go index 8712797cf0..fcb51e650b 100644 --- a/routers/admin/repos.go +++ b/routers/admin/repos.go @@ -34,12 +34,12 @@ func Repos(ctx *context.Context) { func DeleteRepo(ctx *context.Context) { repo, err := models.GetRepositoryByID(ctx.QueryInt64("id")) if err != nil { - ctx.Handle(500, "GetRepositoryByID", err) + ctx.ServerError("GetRepositoryByID", err) return } if err := models.DeleteRepository(ctx.User, repo.MustOwner().ID, repo.ID); err != nil { - ctx.Handle(500, "DeleteRepository", err) + ctx.ServerError("DeleteRepository", err) return } log.Trace("Repository deleted: %s/%s", repo.MustOwner().Name, repo.Name) diff --git a/routers/admin/users.go b/routers/admin/users.go index 02b8334564..eee0c21f44 100644 --- a/routers/admin/users.go +++ b/routers/admin/users.go @@ -47,7 +47,7 @@ func NewUser(ctx *context.Context) { sources, err := models.LoginSources() if err != nil { - ctx.Handle(500, "LoginSources", err) + ctx.ServerError("LoginSources", err) return } ctx.Data["Sources"] = sources @@ -64,7 +64,7 @@ func NewUserPost(ctx *context.Context, form auth.AdminCreateUserForm) { sources, err := models.LoginSources() if err != nil { - ctx.Handle(500, "LoginSources", err) + ctx.ServerError("LoginSources", err) return } ctx.Data["Sources"] = sources @@ -108,7 +108,7 @@ func NewUserPost(ctx *context.Context, form auth.AdminCreateUserForm) { ctx.Data["Err_UserName"] = true ctx.RenderWithErr(ctx.Tr("user.form.name_pattern_not_allowed", err.(models.ErrNamePatternNotAllowed).Pattern), tplUserNew, &form) default: - ctx.Handle(500, "CreateUser", err) + ctx.ServerError("CreateUser", err) } return } @@ -126,7 +126,7 @@ func NewUserPost(ctx *context.Context, form auth.AdminCreateUserForm) { func prepareUserInfo(ctx *context.Context) *models.User { u, err := models.GetUserByID(ctx.ParamsInt64(":userid")) if err != nil { - ctx.Handle(500, "GetUserByID", err) + ctx.ServerError("GetUserByID", err) return nil } ctx.Data["User"] = u @@ -134,7 +134,7 @@ func prepareUserInfo(ctx *context.Context) *models.User { if u.LoginSource > 0 { ctx.Data["LoginSource"], err = models.GetLoginSourceByID(u.LoginSource) if err != nil { - ctx.Handle(500, "GetLoginSourceByID", err) + ctx.ServerError("GetLoginSourceByID", err) return nil } } else { @@ -143,7 +143,7 @@ func prepareUserInfo(ctx *context.Context) *models.User { sources, err := models.LoginSources() if err != nil { - ctx.Handle(500, "LoginSources", err) + ctx.ServerError("LoginSources", err) return nil } ctx.Data["Sources"] = sources @@ -197,7 +197,7 @@ func EditUserPost(ctx *context.Context, form auth.AdminEditUserForm) { u.Passwd = form.Password var err error if u.Salt, err = models.GetUserSalt(); err != nil { - ctx.Handle(500, "UpdateUser", err) + ctx.ServerError("UpdateUser", err) return } u.HashPassword() @@ -221,7 +221,7 @@ func EditUserPost(ctx *context.Context, form auth.AdminEditUserForm) { ctx.Data["Err_Email"] = true ctx.RenderWithErr(ctx.Tr("form.email_been_used"), tplUserEdit, &form) } else { - ctx.Handle(500, "UpdateUser", err) + ctx.ServerError("UpdateUser", err) } return } @@ -235,7 +235,7 @@ func EditUserPost(ctx *context.Context, form auth.AdminEditUserForm) { func DeleteUser(ctx *context.Context) { u, err := models.GetUserByID(ctx.ParamsInt64(":userid")) if err != nil { - ctx.Handle(500, "GetUserByID", err) + ctx.ServerError("GetUserByID", err) return } @@ -252,7 +252,7 @@ func DeleteUser(ctx *context.Context) { "redirect": setting.AppSubURL + "/admin/users/" + ctx.Params(":userid"), }) default: - ctx.Handle(500, "DeleteUser", err) + ctx.ServerError("DeleteUser", err) } return } diff --git a/routers/api/v1/repo/fork.go b/routers/api/v1/repo/fork.go index ec1b37b91a..694d7a9471 100644 --- a/routers/api/v1/repo/fork.go +++ b/routers/api/v1/repo/fork.go @@ -91,7 +91,7 @@ func CreateFork(ctx *context.APIContext, form api.CreateForkOption) { } isMember, err := org.IsOrgMember(ctx.User.ID) if err != nil { - ctx.Handle(500, "IsOrgMember", err) + ctx.ServerError("IsOrgMember", err) return } else if !isMember { ctx.Status(403) diff --git a/routers/api/v1/repo/label.go b/routers/api/v1/repo/label.go index cb724c7182..b9401cef68 100644 --- a/routers/api/v1/repo/label.go +++ b/routers/api/v1/repo/label.go @@ -193,7 +193,7 @@ func EditLabel(ctx *context.APIContext, form api.EditLabelOption) { label.Color = *form.Color } if err := models.UpdateLabel(label); err != nil { - ctx.Handle(500, "UpdateLabel", err) + ctx.ServerError("UpdateLabel", err) return } ctx.JSON(200, label.APIFormat()) diff --git a/routers/api/v1/repo/milestone.go b/routers/api/v1/repo/milestone.go index 29bab67ac5..53edd3230c 100644 --- a/routers/api/v1/repo/milestone.go +++ b/routers/api/v1/repo/milestone.go @@ -180,7 +180,7 @@ func EditMilestone(ctx *context.APIContext, form api.EditMilestoneOption) { } if err := models.UpdateMilestone(milestone); err != nil { - ctx.Handle(500, "UpdateMilestone", err) + ctx.ServerError("UpdateMilestone", err) return } ctx.JSON(200, milestone.APIFormat()) diff --git a/routers/api/v1/repo/pull.go b/routers/api/v1/repo/pull.go index 7e011219be..742c0bccf9 100644 --- a/routers/api/v1/repo/pull.go +++ b/routers/api/v1/repo/pull.go @@ -465,7 +465,7 @@ func MergePullRequest(ctx *context.APIContext, form auth.MergePullRequestForm) { pr, err := models.GetPullRequestByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index")) if err != nil { if models.IsErrPullRequestNotExist(err) { - ctx.Handle(404, "GetPullRequestByIndex", err) + ctx.NotFound("GetPullRequestByIndex", err) } else { ctx.Error(500, "GetPullRequestByIndex", err) } @@ -473,7 +473,7 @@ func MergePullRequest(ctx *context.APIContext, form auth.MergePullRequestForm) { } if err = pr.GetHeadRepo(); err != nil { - ctx.Handle(500, "GetHeadRepo", err) + ctx.ServerError("GetHeadRepo", err) return } @@ -560,9 +560,9 @@ func parseCompareInfo(ctx *context.APIContext, form api.CreatePullRequestOption) headUser, err = models.GetUserByName(headInfos[0]) if err != nil { if models.IsErrUserNotExist(err) { - ctx.Handle(404, "GetUserByName", nil) + ctx.NotFound("GetUserByName", nil) } else { - ctx.Handle(500, "GetUserByName", err) + ctx.ServerError("GetUserByName", err) } return nil, nil, nil, nil, "", "" } diff --git a/routers/api/v1/repo/release.go b/routers/api/v1/repo/release.go index 17cddc5652..f5b529ac6a 100644 --- a/routers/api/v1/repo/release.go +++ b/routers/api/v1/repo/release.go @@ -132,7 +132,7 @@ func CreateRelease(ctx *context.APIContext, form api.CreateReleaseOption) { rel, err := models.GetRelease(ctx.Repo.Repository.ID, form.TagName) if err != nil { if !models.IsErrReleaseNotExist(err) { - ctx.Handle(500, "GetRelease", err) + ctx.ServerError("GetRelease", err) return } rel = &models.Release{ @@ -169,7 +169,7 @@ func CreateRelease(ctx *context.APIContext, form api.CreateReleaseOption) { rel.IsTag = false if err = models.UpdateRelease(ctx.Repo.GitRepo, rel, nil); err != nil { - ctx.Handle(500, "UpdateRelease", err) + ctx.ServerError("UpdateRelease", err) return } } diff --git a/routers/api/v1/repo/repo.go b/routers/api/v1/repo/repo.go index c9c7aa805d..b85ffd8d2f 100644 --- a/routers/api/v1/repo/repo.go +++ b/routers/api/v1/repo/repo.go @@ -258,7 +258,7 @@ func CreateOrgRepo(ctx *context.APIContext, opt api.CreateRepoOption) { isOwner, err := org.IsOwnedBy(ctx.User.ID) if err != nil { - ctx.Handle(500, "IsOwnedBy", err) + ctx.ServerError("IsOwnedBy", err) return } else if !isOwner { ctx.Error(403, "", "Given user is not owner of organization.") diff --git a/routers/home.go b/routers/home.go index ce4e0be98d..74125aa2df 100644 --- a/routers/home.go +++ b/routers/home.go @@ -117,7 +117,7 @@ func RenderRepoSearch(ctx *context.Context, opts *RepoSearchOptions) { AllPublic: true, }) if err != nil { - ctx.Handle(500, "SearchRepositoryByName", err) + ctx.ServerError("SearchRepositoryByName", err) return } ctx.Data["Keyword"] = keyword @@ -185,7 +185,7 @@ func RenderUserSearch(ctx *context.Context, opts *models.SearchUserOptions, tplN if len(opts.Keyword) == 0 || isKeywordValid(opts.Keyword) { users, count, err = models.SearchUsers(opts) if err != nil { - ctx.Handle(500, "SearchUsers", err) + ctx.ServerError("SearchUsers", err) return } } @@ -226,5 +226,5 @@ func ExploreOrganizations(ctx *context.Context) { // NotFound render 404 page func NotFound(ctx *context.Context) { ctx.Data["Title"] = "Page Not Found" - ctx.Handle(404, "home.NotFound", nil) + ctx.NotFound("home.NotFound", nil) } diff --git a/routers/install.go b/routers/install.go index df65d4fabf..c180d947fc 100644 --- a/routers/install.go +++ b/routers/install.go @@ -33,7 +33,7 @@ const ( // InstallInit prepare for rendering installation page func InstallInit(ctx *context.Context) { if setting.InstallLock { - ctx.Handle(404, "Install", errors.New("Installation is prohibited")) + ctx.NotFound("Install", errors.New("Installation is prohibited")) return } diff --git a/routers/org/members.go b/routers/org/members.go index aa3646d1e0..8a243c87be 100644 --- a/routers/org/members.go +++ b/routers/org/members.go @@ -26,7 +26,7 @@ func Members(ctx *context.Context) { ctx.Data["PageIsOrgMembers"] = true if err := org.GetMembers(); err != nil { - ctx.Handle(500, "GetMembers", err) + ctx.ServerError("GetMembers", err) return } ctx.Data["Members"] = org.Members diff --git a/routers/org/org.go b/routers/org/org.go index d0988bfcf5..665d1a71fc 100644 --- a/routers/org/org.go +++ b/routers/org/org.go @@ -22,9 +22,13 @@ const ( // Create render the page for create organization func Create(ctx *context.Context) { + if !ctx.User.CanCreateOrganization() { + ctx.NotFound("CanCreateOrganization", nil) + } + ctx.Data["Title"] = ctx.Tr("new_org") if !ctx.User.CanCreateOrganization() { - ctx.Handle(500, "Not allowed", errors.New(ctx.Tr("org.form.create_org_not_allowed"))) + ctx.ServerError("Not allowed", errors.New(ctx.Tr("org.form.create_org_not_allowed"))) return } ctx.HTML(200, tplCreateOrg) @@ -32,6 +36,10 @@ func Create(ctx *context.Context) { // CreatePost response for create organization func CreatePost(ctx *context.Context, form auth.CreateOrgForm) { + if !ctx.User.CanCreateOrganization() { + ctx.NotFound("CanCreateOrganization", nil) + } + ctx.Data["Title"] = ctx.Tr("new_org") if ctx.HasError() { @@ -57,7 +65,7 @@ func CreatePost(ctx *context.Context, form auth.CreateOrgForm) { case models.IsErrUserNotAllowedCreateOrg(err): ctx.RenderWithErr(ctx.Tr("org.form.create_org_not_allowed"), tplCreateOrg, &form) default: - ctx.Handle(500, "CreateOrganization", err) + ctx.ServerError("CreateOrganization", err) } return } diff --git a/routers/org/setting.go b/routers/org/setting.go index 4faed77d0d..937697d07e 100644 --- a/routers/org/setting.go +++ b/routers/org/setting.go @@ -48,7 +48,7 @@ func SettingsPost(ctx *context.Context, form auth.UpdateOrgSettingForm) { if org.LowerName != strings.ToLower(form.Name) { isExist, err := models.IsUserExist(org.ID, form.Name) if err != nil { - ctx.Handle(500, "IsUserExist", err) + ctx.ServerError("IsUserExist", err) return } else if isExist { ctx.Data["OrgName"] = true @@ -59,7 +59,7 @@ func SettingsPost(ctx *context.Context, form auth.UpdateOrgSettingForm) { ctx.Data["OrgName"] = true ctx.RenderWithErr(ctx.Tr("form.illegal_username"), tplSettingsOptions, &form) } else { - ctx.Handle(500, "ChangeUserName", err) + ctx.ServerError("ChangeUserName", err) } return } @@ -80,7 +80,7 @@ func SettingsPost(ctx *context.Context, form auth.UpdateOrgSettingForm) { org.Website = form.Website org.Location = form.Location if err := models.UpdateUser(org); err != nil { - ctx.Handle(500, "UpdateUser", err) + ctx.ServerError("UpdateUser", err) return } log.Trace("Organization setting updated: %s", org.Name) @@ -120,7 +120,7 @@ func SettingsDelete(ctx *context.Context) { if models.IsErrUserNotExist(err) { ctx.RenderWithErr(ctx.Tr("form.enterred_invalid_password"), tplSettingsDelete, nil) } else { - ctx.Handle(500, "UserSignIn", err) + ctx.ServerError("UserSignIn", err) } return } @@ -130,7 +130,7 @@ func SettingsDelete(ctx *context.Context) { ctx.Flash.Error(ctx.Tr("form.org_still_own_repo")) ctx.Redirect(ctx.Org.OrgLink + "/settings/delete") } else { - ctx.Handle(500, "DeleteOrganization", err) + ctx.ServerError("DeleteOrganization", err) } } else { log.Trace("Organization deleted: %s", org.Name) @@ -151,7 +151,7 @@ func Webhooks(ctx *context.Context) { ws, err := models.GetWebhooksByOrgID(ctx.Org.Organization.ID) if err != nil { - ctx.Handle(500, "GetWebhooksByOrgId", err) + ctx.ServerError("GetWebhooksByOrgId", err) return } diff --git a/routers/org/teams.go b/routers/org/teams.go index 7f8b828e82..d894c86614 100644 --- a/routers/org/teams.go +++ b/routers/org/teams.go @@ -37,7 +37,7 @@ func Teams(ctx *context.Context) { for _, t := range org.Teams { if err := t.GetMembers(); err != nil { - ctx.Handle(500, "GetMembers", err) + ctx.ServerError("GetMembers", err) return } } @@ -85,7 +85,7 @@ func TeamsAction(ctx *context.Context) { ctx.Flash.Error(ctx.Tr("form.user_not_exist")) ctx.Redirect(ctx.Org.OrgLink + "/teams/" + ctx.Org.Team.LowerName) } else { - ctx.Handle(500, " GetUserByName", err) + ctx.ServerError(" GetUserByName", err) } return } @@ -142,7 +142,7 @@ func TeamsRepoAction(ctx *context.Context) { ctx.Redirect(ctx.Org.OrgLink + "/teams/" + ctx.Org.Team.LowerName + "/repositories") return } - ctx.Handle(500, "GetRepositoryByName", err) + ctx.ServerError("GetRepositoryByName", err) return } err = ctx.Org.Team.AddRepository(repo) @@ -152,7 +152,7 @@ func TeamsRepoAction(ctx *context.Context) { if err != nil { log.Error(3, "Action(%s): '%s' %v", ctx.Params(":action"), ctx.Org.Team.Name, err) - ctx.Handle(500, "TeamsRepoAction", err) + ctx.ServerError("TeamsRepoAction", err) return } ctx.Redirect(ctx.Org.OrgLink + "/teams/" + ctx.Org.Team.LowerName + "/repositories") @@ -203,7 +203,7 @@ func NewTeamPost(ctx *context.Context, form auth.CreateTeamForm) { case models.IsErrTeamAlreadyExist(err): ctx.RenderWithErr(ctx.Tr("form.team_name_been_taken"), tplTeamNew, &form) default: - ctx.Handle(500, "NewTeam", err) + ctx.ServerError("NewTeam", err) } return } @@ -216,7 +216,7 @@ func TeamMembers(ctx *context.Context) { ctx.Data["Title"] = ctx.Org.Team.Name ctx.Data["PageIsOrgTeams"] = true if err := ctx.Org.Team.GetMembers(); err != nil { - ctx.Handle(500, "GetMembers", err) + ctx.ServerError("GetMembers", err) return } ctx.HTML(200, tplTeamMembers) @@ -227,7 +227,7 @@ func TeamRepositories(ctx *context.Context) { ctx.Data["Title"] = ctx.Org.Team.Name ctx.Data["PageIsOrgTeams"] = true if err := ctx.Org.Team.GetRepositories(); err != nil { - ctx.Handle(500, "GetRepositories", err) + ctx.ServerError("GetRepositories", err) return } ctx.HTML(200, tplTeamRepositories) @@ -285,7 +285,7 @@ func EditTeamPost(ctx *context.Context, form auth.CreateTeamForm) { case models.IsErrTeamAlreadyExist(err): ctx.RenderWithErr(ctx.Tr("form.team_name_been_taken"), tplTeamNew, &form) default: - ctx.Handle(500, "UpdateTeam", err) + ctx.ServerError("UpdateTeam", err) } return } diff --git a/routers/repo/activity.go b/routers/repo/activity.go index fbe51e152e..a0a25dc936 100644 --- a/routers/repo/activity.go +++ b/routers/repo/activity.go @@ -48,7 +48,7 @@ func Activity(ctx *context.Context) { ctx.Repo.Repository.UnitEnabled(models.UnitTypeReleases), ctx.Repo.Repository.UnitEnabled(models.UnitTypeIssues), ctx.Repo.Repository.UnitEnabled(models.UnitTypePullRequests)); err != nil { - ctx.Handle(500, "GetActivityStats", err) + ctx.ServerError("GetActivityStats", err) return } diff --git a/routers/repo/branch.go b/routers/repo/branch.go index c56e8e86b2..7b1e2a8bbe 100644 --- a/routers/repo/branch.go +++ b/routers/repo/branch.go @@ -136,7 +136,7 @@ func deleteBranch(ctx *context.Context, branchName string) error { func loadBranches(ctx *context.Context) []*Branch { rawBranches, err := ctx.Repo.Repository.GetBranches() if err != nil { - ctx.Handle(500, "GetBranches", err) + ctx.ServerError("GetBranches", err) return nil } @@ -144,13 +144,13 @@ func loadBranches(ctx *context.Context) []*Branch { for i := range rawBranches { commit, err := rawBranches[i].GetCommit() if err != nil { - ctx.Handle(500, "GetCommit", err) + ctx.ServerError("GetCommit", err) return nil } isProtected, err := ctx.Repo.Repository.IsProtectedBranch(rawBranches[i].Name, ctx.User) if err != nil { - ctx.Handle(500, "IsProtectedBranch", err) + ctx.ServerError("IsProtectedBranch", err) return nil } @@ -164,7 +164,7 @@ func loadBranches(ctx *context.Context) []*Branch { if ctx.Repo.IsWriter() { deletedBranches, err := getDeletedBranches(ctx) if err != nil { - ctx.Handle(500, "getDeletedBranches", err) + ctx.ServerError("getDeletedBranches", err) return nil } branches = append(branches, deletedBranches...) @@ -196,7 +196,7 @@ func getDeletedBranches(ctx *context.Context) ([]*Branch, error) { // CreateBranch creates new branch in repository func CreateBranch(ctx *context.Context, form auth.NewBranchForm) { if !ctx.Repo.CanCreateBranch() { - ctx.Handle(404, "CreateBranch", nil) + ctx.NotFound("CreateBranch", nil) return } @@ -232,7 +232,7 @@ func CreateBranch(ctx *context.Context, form auth.NewBranchForm) { return } - ctx.Handle(500, "CreateNewBranch", err) + ctx.ServerError("CreateNewBranch", err) return } diff --git a/routers/repo/commit.go b/routers/repo/commit.go index 2fcb65557d..02ccb0caab 100644 --- a/routers/repo/commit.go +++ b/routers/repo/commit.go @@ -40,14 +40,14 @@ func RefCommits(ctx *context.Context) { func Commits(ctx *context.Context) { ctx.Data["PageIsCommits"] = true if ctx.Repo.Commit == nil { - ctx.Handle(404, "Commit not found", nil) + ctx.NotFound("Commit not found", nil) return } ctx.Data["PageIsViewCode"] = true commitsCount, err := ctx.Repo.GetCommitsCount() if err != nil { - ctx.Handle(500, "GetCommitsCount", err) + ctx.ServerError("GetCommitsCount", err) return } @@ -60,7 +60,7 @@ func Commits(ctx *context.Context) { // Both `git log branchName` and `git log commitId` work. commits, err := ctx.Repo.Commit.CommitsByRange(page) if err != nil { - ctx.Handle(500, "CommitsByRange", err) + ctx.ServerError("CommitsByRange", err) return } commits = models.ValidateCommitsWithEmails(commits) @@ -82,13 +82,13 @@ func Graph(ctx *context.Context) { commitsCount, err := ctx.Repo.GetCommitsCount() if err != nil { - ctx.Handle(500, "GetCommitsCount", err) + ctx.ServerError("GetCommitsCount", err) return } graph, err := models.GetCommitGraph(ctx.Repo.GitRepo) if err != nil { - ctx.Handle(500, "GetCommitGraph", err) + ctx.ServerError("GetCommitGraph", err) return } @@ -116,7 +116,7 @@ func SearchCommits(ctx *context.Context) { commits, err := ctx.Repo.Commit.SearchCommits(keyword, all) if err != nil { - ctx.Handle(500, "SearchCommits", err) + ctx.ServerError("SearchCommits", err) return } commits = models.ValidateCommitsWithEmails(commits) @@ -148,10 +148,10 @@ func FileHistory(ctx *context.Context) { branchName := ctx.Repo.BranchName commitsCount, err := ctx.Repo.GitRepo.FileCommitsCount(branchName, fileName) if err != nil { - ctx.Handle(500, "FileCommitsCount", err) + ctx.ServerError("FileCommitsCount", err) return } else if commitsCount == 0 { - ctx.Handle(404, "FileCommitsCount", nil) + ctx.NotFound("FileCommitsCount", nil) return } @@ -163,7 +163,7 @@ func FileHistory(ctx *context.Context) { commits, err := ctx.Repo.GitRepo.CommitsByFileAndRange(branchName, fileName, page) if err != nil { - ctx.Handle(500, "CommitsByFileAndRange", err) + ctx.ServerError("CommitsByFileAndRange", err) return } commits = models.ValidateCommitsWithEmails(commits) @@ -191,9 +191,9 @@ func Diff(ctx *context.Context) { commit, err := ctx.Repo.GitRepo.GetCommit(commitID) if err != nil { if git.IsErrNotExist(err) { - ctx.Handle(404, "Repo.GitRepo.GetCommit", err) + ctx.NotFound("Repo.GitRepo.GetCommit", err) } else { - ctx.Handle(500, "Repo.GitRepo.GetCommit", err) + ctx.ServerError("Repo.GitRepo.GetCommit", err) } return } @@ -212,7 +212,7 @@ func Diff(ctx *context.Context) { commitID, setting.Git.MaxGitDiffLines, setting.Git.MaxGitDiffLineCharacters, setting.Git.MaxGitDiffFiles) if err != nil { - ctx.Handle(404, "GetDiffCommit", err) + ctx.NotFound("GetDiffCommit", err) return } @@ -221,7 +221,7 @@ func Diff(ctx *context.Context) { sha, err := commit.ParentID(i) parents[i] = sha.String() if err != nil { - ctx.Handle(404, "repo.Diff", err) + ctx.NotFound("repo.Diff", err) return } } @@ -253,7 +253,7 @@ func RawDiff(ctx *context.Context) { models.RawDiffType(ctx.Params(":ext")), ctx.Resp, ); err != nil { - ctx.Handle(500, "GetRawDiff", err) + ctx.ServerError("GetRawDiff", err) return } } @@ -269,7 +269,7 @@ func CompareDiff(ctx *context.Context) { commit, err := ctx.Repo.GitRepo.GetCommit(afterCommitID) if err != nil { - ctx.Handle(404, "GetCommit", err) + ctx.NotFound("GetCommit", err) return } @@ -277,13 +277,13 @@ func CompareDiff(ctx *context.Context) { afterCommitID, setting.Git.MaxGitDiffLines, setting.Git.MaxGitDiffLineCharacters, setting.Git.MaxGitDiffFiles) if err != nil { - ctx.Handle(404, "GetDiffRange", err) + ctx.NotFound("GetDiffRange", err) return } commits, err := commit.CommitsBeforeUntil(beforeCommitID) if err != nil { - ctx.Handle(500, "CommitsBeforeUntil", err) + ctx.ServerError("CommitsBeforeUntil", err) return } commits = models.ValidateCommitsWithEmails(commits) diff --git a/routers/repo/download.go b/routers/repo/download.go index 78c4b519be..820a98c0dc 100644 --- a/routers/repo/download.go +++ b/routers/repo/download.go @@ -59,13 +59,13 @@ func SingleDownload(ctx *context.Context) { blob, err := ctx.Repo.Commit.GetBlobByPath(ctx.Repo.TreePath) if err != nil { if git.IsErrNotExist(err) { - ctx.Handle(404, "GetBlobByPath", nil) + ctx.NotFound("GetBlobByPath", nil) } else { - ctx.Handle(500, "GetBlobByPath", err) + ctx.ServerError("GetBlobByPath", err) } return } if err = ServeBlob(ctx, blob); err != nil { - ctx.Handle(500, "ServeBlob", err) + ctx.ServerError("ServeBlob", err) } } diff --git a/routers/repo/editor.go b/routers/repo/editor.go index 82b04a84d2..6c6bf304fc 100644 --- a/routers/repo/editor.go +++ b/routers/repo/editor.go @@ -73,19 +73,19 @@ func editFile(ctx *context.Context, isNewFile bool) { // No way to edit a directory online. if entry.IsDir() { - ctx.Handle(404, "entry.IsDir", nil) + ctx.NotFound("entry.IsDir", nil) return } blob := entry.Blob() if blob.Size() >= setting.UI.MaxDisplayFileSize { - ctx.Handle(404, "blob.Size", err) + ctx.NotFound("blob.Size", err) return } dataRc, err := blob.Data() if err != nil { - ctx.Handle(404, "blob.Data", err) + ctx.NotFound("blob.Data", err) return } @@ -98,7 +98,7 @@ func editFile(ctx *context.Context, isNewFile bool) { // Only text file are editable online. if !base.IsTextFile(buf) { - ctx.Handle(404, "base.IsTextFile", nil) + ctx.NotFound("base.IsTextFile", nil) return } @@ -214,7 +214,7 @@ func editFilePost(ctx *context.Context, form auth.EditRepoFileForm, isNewFile bo break } - ctx.Handle(500, "Repo.Commit.GetTreeEntryByPath", err) + ctx.ServerError("Repo.Commit.GetTreeEntryByPath", err) return } if index != len(treeNames)-1 { @@ -244,14 +244,14 @@ func editFilePost(ctx *context.Context, form auth.EditRepoFileForm, isNewFile bo ctx.Data["Err_TreePath"] = true ctx.RenderWithErr(ctx.Tr("repo.editor.file_editing_no_longer_exists", oldTreePath), tplEditFile, &form) } else { - ctx.Handle(500, "GetTreeEntryByPath", err) + ctx.ServerError("GetTreeEntryByPath", err) } return } if lastCommit != ctx.Repo.CommitID { files, err := ctx.Repo.Commit.GetFilesChangedSinceCommit(lastCommit) if err != nil { - ctx.Handle(500, "GetFilesChangedSinceCommit", err) + ctx.ServerError("GetFilesChangedSinceCommit", err) return } @@ -269,7 +269,7 @@ func editFilePost(ctx *context.Context, form auth.EditRepoFileForm, isNewFile bo entry, err := ctx.Repo.Commit.GetTreeEntryByPath(form.TreePath) if err != nil { if !git.IsErrNotExist(err) { - ctx.Handle(500, "GetTreeEntryByPath", err) + ctx.ServerError("GetTreeEntryByPath", err) return } } @@ -422,7 +422,7 @@ func DeleteFilePost(ctx *context.Context, form auth.DeleteRepoFileForm) { TreePath: ctx.Repo.TreePath, Message: message, }); err != nil { - ctx.Handle(500, "DeleteRepoFile", err) + ctx.ServerError("DeleteRepoFile", err) return } @@ -521,7 +521,7 @@ func UploadFilePost(ctx *context.Context, form auth.UploadRepoFileForm) { break } - ctx.Handle(500, "Repo.Commit.GetTreeEntryByPath", err) + ctx.ServerError("Repo.Commit.GetTreeEntryByPath", err) return } diff --git a/routers/repo/http.go b/routers/repo/http.go index c1fdad5350..08ccf3ed65 100644 --- a/routers/repo/http.go +++ b/routers/repo/http.go @@ -120,7 +120,7 @@ func HTTP(ctx *context.Context) { authUser, err = models.UserSignIn(authUsername, authPasswd) if err != nil { if !models.IsErrUserNotExist(err) { - ctx.Handle(http.StatusInternalServerError, "UserSignIn error: %v", err) + ctx.ServerError("UserSignIn error: %v", err) return } } @@ -140,7 +140,7 @@ func HTTP(ctx *context.Context) { if models.IsErrUserNotExist(err) { ctx.HandleText(http.StatusUnauthorized, "invalid credentials") } else { - ctx.Handle(http.StatusInternalServerError, "GetUserByName", err) + ctx.ServerError("GetUserByName", err) } return } @@ -152,7 +152,7 @@ func HTTP(ctx *context.Context) { if models.IsErrAccessTokenNotExist(err) || models.IsErrAccessTokenEmpty(err) { ctx.HandleText(http.StatusUnauthorized, "invalid credentials") } else { - ctx.Handle(http.StatusInternalServerError, "GetAccessTokenBySha", err) + ctx.ServerError("GetAccessTokenBySha", err) } return } @@ -160,7 +160,7 @@ func HTTP(ctx *context.Context) { if isUsernameToken { authUser, err = models.GetUserByID(token.UID) if err != nil { - ctx.Handle(http.StatusInternalServerError, "GetUserByID", err) + ctx.ServerError("GetUserByID", err) return } } else if authUser.ID != token.UID { @@ -170,7 +170,7 @@ func HTTP(ctx *context.Context) { token.UpdatedUnix = util.TimeStampNow() if err = models.UpdateAccessToken(token); err != nil { - ctx.Handle(http.StatusInternalServerError, "UpdateAccessToken", err) + ctx.ServerError("UpdateAccessToken", err) } } else { _, err = models.GetTwoFactorByUID(authUser.ID) @@ -180,7 +180,7 @@ func HTTP(ctx *context.Context) { ctx.HandleText(http.StatusUnauthorized, "Users with two-factor authentication enabled cannot perform HTTP/HTTPS operations via plain username and password. Please create and use a personal access token on the user settings page") return } else if !models.IsErrTwoFactorNotEnrolled(err) { - ctx.Handle(http.StatusInternalServerError, "IsErrTwoFactorNotEnrolled", err) + ctx.ServerError("IsErrTwoFactorNotEnrolled", err) return } } @@ -188,13 +188,13 @@ func HTTP(ctx *context.Context) { if !isPublicPull { has, err := models.HasAccess(authUser.ID, repo, accessMode) if err != nil { - ctx.Handle(http.StatusInternalServerError, "HasAccess", err) + ctx.ServerError("HasAccess", err) return } else if !has { if accessMode == models.AccessModeRead { has, err = models.HasAccess(authUser.ID, repo, models.AccessModeWrite) if err != nil { - ctx.Handle(http.StatusInternalServerError, "HasAccess2", err) + ctx.ServerError("HasAccess2", err) return } else if !has { ctx.HandleText(http.StatusForbidden, "User permission denied") @@ -501,7 +501,7 @@ func HTTPBackend(ctx *context.Context, cfg *serviceConfig) http.HandlerFunc { dir, err := getGitRepoPath(m[1]) if err != nil { log.GitLogger.Error(4, err.Error()) - ctx.Handle(http.StatusNotFound, "HTTPBackend", err) + ctx.NotFound("HTTPBackend", err) return } @@ -510,7 +510,7 @@ func HTTPBackend(ctx *context.Context, cfg *serviceConfig) http.HandlerFunc { } } - ctx.Handle(http.StatusNotFound, "HTTPBackend", nil) + ctx.NotFound("HTTPBackend", nil) return } } diff --git a/routers/repo/issue.go b/routers/repo/issue.go index e4aecf152e..230b0e939d 100644 --- a/routers/repo/issue.go +++ b/routers/repo/issue.go @@ -64,7 +64,7 @@ var ( func MustEnableIssues(ctx *context.Context) { if !ctx.Repo.Repository.UnitEnabled(models.UnitTypeIssues) && !ctx.Repo.Repository.UnitEnabled(models.UnitTypeExternalTracker) { - ctx.Handle(404, "MustEnableIssues", nil) + ctx.NotFound("MustEnableIssues", nil) return } @@ -78,7 +78,7 @@ func MustEnableIssues(ctx *context.Context) { // MustAllowPulls check if repository enable pull requests func MustAllowPulls(ctx *context.Context) { if !ctx.Repo.Repository.AllowsPulls() { - ctx.Handle(404, "MustAllowPulls", nil) + ctx.NotFound("MustAllowPulls", nil) return } @@ -167,7 +167,7 @@ func Issues(ctx *context.Context) { IssueIDs: issueIDs, }) if err != nil { - ctx.Handle(500, "GetIssueStats", err) + ctx.ServerError("GetIssueStats", err) return } } @@ -204,7 +204,7 @@ func Issues(ctx *context.Context) { IssueIDs: issueIDs, }) if err != nil { - ctx.Handle(500, "Issues", err) + ctx.ServerError("Issues", err) return } } @@ -215,7 +215,7 @@ func Issues(ctx *context.Context) { if !ctx.IsSigned { issues[i].IsRead = true } else if err = issues[i].GetIsRead(ctx.User.ID); err != nil { - ctx.Handle(500, "GetIsRead", err) + ctx.ServerError("GetIsRead", err) return } } @@ -224,14 +224,14 @@ func Issues(ctx *context.Context) { // Get milestones. ctx.Data["Milestones"], err = models.GetMilestonesByRepoID(repo.ID) if err != nil { - ctx.Handle(500, "GetAllRepoMilestones", err) + ctx.ServerError("GetAllRepoMilestones", err) return } // Get assignees. ctx.Data["Assignees"], err = repo.GetAssignees() if err != nil { - ctx.Handle(500, "GetAssignees", err) + ctx.ServerError("GetAssignees", err) return } @@ -261,18 +261,18 @@ func RetrieveRepoMilestonesAndAssignees(ctx *context.Context, repo *models.Repos var err error ctx.Data["OpenMilestones"], err = models.GetMilestones(repo.ID, -1, false, "") if err != nil { - ctx.Handle(500, "GetMilestones", err) + ctx.ServerError("GetMilestones", err) return } ctx.Data["ClosedMilestones"], err = models.GetMilestones(repo.ID, -1, true, "") if err != nil { - ctx.Handle(500, "GetMilestones", err) + ctx.ServerError("GetMilestones", err) return } ctx.Data["Assignees"], err = repo.GetAssignees() if err != nil { - ctx.Handle(500, "GetAssignees", err) + ctx.ServerError("GetAssignees", err) return } } @@ -285,7 +285,7 @@ func RetrieveRepoMetas(ctx *context.Context, repo *models.Repository) []*models. labels, err := models.GetLabelsByRepoID(repo.ID, "") if err != nil { - ctx.Handle(500, "GetLabelsByRepoID", err) + ctx.ServerError("GetLabelsByRepoID", err) return nil } ctx.Data["Labels"] = labels @@ -297,7 +297,7 @@ func RetrieveRepoMetas(ctx *context.Context, repo *models.Repository) []*models. brs, err := ctx.Repo.GitRepo.GetBranches() if err != nil { - ctx.Handle(500, "GetBranches", err) + ctx.ServerError("GetBranches", err) return nil } ctx.Data["Branches"] = brs @@ -406,7 +406,7 @@ func ValidateRepoMetas(ctx *context.Context, form auth.CreateIssueForm) ([]int64 if milestoneID > 0 { ctx.Data["Milestone"], err = repo.GetMilestoneByID(milestoneID) if err != nil { - ctx.Handle(500, "GetMilestoneByID", err) + ctx.ServerError("GetMilestoneByID", err) return nil, 0, 0 } ctx.Data["milestone_id"] = milestoneID @@ -417,7 +417,7 @@ func ValidateRepoMetas(ctx *context.Context, form auth.CreateIssueForm) ([]int64 if assigneeID > 0 { ctx.Data["Assignee"], err = repo.GetAssigneeByID(assigneeID) if err != nil { - ctx.Handle(500, "GetAssigneeByID", err) + ctx.ServerError("GetAssigneeByID", err) return nil, 0, 0 } ctx.Data["assignee_id"] = assigneeID @@ -465,7 +465,7 @@ func NewIssuePost(ctx *context.Context, form auth.CreateIssueForm) { Ref: form.Ref, } if err := models.NewIssue(repo, issue, labelIDs, attachments); err != nil { - ctx.Handle(500, "NewIssue", err) + ctx.ServerError("NewIssue", err) return } @@ -505,9 +505,9 @@ func ViewIssue(ctx *context.Context) { issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index")) if err != nil { if models.IsErrIssueNotExist(err) { - ctx.Handle(404, "GetIssueByIndex", err) + ctx.NotFound("GetIssueByIndex", err) } else { - ctx.Handle(500, "GetIssueByIndex", err) + ctx.ServerError("GetIssueByIndex", err) } return } @@ -518,7 +518,7 @@ func ViewIssue(ctx *context.Context) { if ctx.User != nil { iw, exists, err = models.GetIssueWatch(ctx.User.ID, issue.ID) if err != nil { - ctx.Handle(500, "GetIssueWatch", err) + ctx.ServerError("GetIssueWatch", err) return } if !exists { @@ -581,7 +581,7 @@ func ViewIssue(ctx *context.Context) { } labels, err := models.GetLabelsByRepoID(repo.ID, "") if err != nil { - ctx.Handle(500, "GetLabelsByRepoID", err) + ctx.ServerError("GetLabelsByRepoID", err) return } hasSelected := false @@ -605,7 +605,7 @@ func ViewIssue(ctx *context.Context) { if ctx.IsSigned { // Update issue-user. if err = issue.ReadBy(ctx.User.ID); err != nil { - ctx.Handle(500, "ReadBy", err) + ctx.ServerError("ReadBy", err) return } } @@ -625,7 +625,7 @@ func ViewIssue(ctx *context.Context) { var exists bool var sw *models.Stopwatch if exists, sw, err = models.HasUserStopwatch(ctx.User.ID); err != nil { - ctx.Handle(500, "HasUserStopwatch", err) + ctx.ServerError("HasUserStopwatch", err) return } ctx.Data["HasUserStopwatch"] = exists @@ -633,7 +633,7 @@ func ViewIssue(ctx *context.Context) { // Add warning if the user has already a stopwatch var otherIssue *models.Issue if otherIssue, err = models.GetIssueByID(sw.IssueID); err != nil { - ctx.Handle(500, "GetIssueByID", err) + ctx.ServerError("GetIssueByID", err) return } // Add link to the issue of the already running stopwatch @@ -645,7 +645,7 @@ func ViewIssue(ctx *context.Context) { ctx.Data["CanUseTimetracker"] = false } if ctx.Data["WorkingUsers"], err = models.TotalTimes(models.FindTrackedTimesOptions{IssueID: issue.ID}); err != nil { - ctx.Handle(500, "TotalTimes", err) + ctx.ServerError("TotalTimes", err) return } } @@ -666,7 +666,7 @@ func ViewIssue(ctx *context.Context) { comment.ShowTag, err = commentTag(repo, comment.Poster, issue) if err != nil { - ctx.Handle(500, "commentTag", err) + ctx.ServerError("commentTag", err) return } marked[comment.PosterID] = comment.ShowTag @@ -683,12 +683,12 @@ func ViewIssue(ctx *context.Context) { } } else if comment.Type == models.CommentTypeLabel { if err = comment.LoadLabel(); err != nil { - ctx.Handle(500, "LoadLabel", err) + ctx.ServerError("LoadLabel", err) return } } else if comment.Type == models.CommentTypeMilestone { if err = comment.LoadMilestone(); err != nil { - ctx.Handle(500, "LoadMilestone", err) + ctx.ServerError("LoadMilestone", err) return } ghostMilestone := &models.Milestone{ @@ -703,7 +703,7 @@ func ViewIssue(ctx *context.Context) { } } else if comment.Type == models.CommentTypeAssignees { if err = comment.LoadAssignees(); err != nil { - ctx.Handle(500, "LoadAssignees", err) + ctx.ServerError("LoadAssignees", err) return } } @@ -729,7 +729,7 @@ func ViewIssue(ctx *context.Context) { prUnit, err := repo.GetUnit(models.UnitTypePullRequests) if err != nil { - ctx.Handle(500, "GetUnit", err) + ctx.ServerError("GetUnit", err) return } prConfig := prUnit.PullRequestsConfig() @@ -771,7 +771,7 @@ func GetActionIssue(ctx *context.Context) *models.Issue { return nil } if err = issue.LoadAttributes(); err != nil { - ctx.Handle(500, "LoadAttributes", nil) + ctx.ServerError("LoadAttributes", nil) return nil } return issue @@ -780,7 +780,7 @@ func GetActionIssue(ctx *context.Context) *models.Issue { func checkIssueRights(ctx *context.Context, issue *models.Issue) { if issue.IsPull && !ctx.Repo.Repository.UnitEnabled(models.UnitTypePullRequests) || !issue.IsPull && !ctx.Repo.Repository.UnitEnabled(models.UnitTypeIssues) { - ctx.Handle(404, "IssueOrPullRequestUnitNotAllowed", nil) + ctx.NotFound("IssueOrPullRequestUnitNotAllowed", nil) } } @@ -793,14 +793,14 @@ func getActionIssues(ctx *context.Context) []*models.Issue { for _, stringIssueID := range strings.Split(commaSeparatedIssueIDs, ",") { issueID, err := strconv.ParseInt(stringIssueID, 10, 64) if err != nil { - ctx.Handle(500, "ParseInt", err) + ctx.ServerError("ParseInt", err) return nil } issueIDs = append(issueIDs, issueID) } issues, err := models.GetIssuesByIDs(issueIDs) if err != nil { - ctx.Handle(500, "GetIssuesByIDs", err) + ctx.ServerError("GetIssuesByIDs", err) return nil } // Check access rights for all issues @@ -808,11 +808,11 @@ func getActionIssues(ctx *context.Context) []*models.Issue { prUnitEnabled := ctx.Repo.Repository.UnitEnabled(models.UnitTypePullRequests) for _, issue := range issues { if issue.IsPull && !prUnitEnabled || !issue.IsPull && !issueUnitEnabled { - ctx.Handle(404, "IssueOrPullRequestUnitNotAllowed", nil) + ctx.NotFound("IssueOrPullRequestUnitNotAllowed", nil) return nil } if err = issue.LoadAttributes(); err != nil { - ctx.Handle(500, "LoadAttributes", err) + ctx.ServerError("LoadAttributes", err) return nil } } @@ -838,7 +838,7 @@ func UpdateIssueTitle(ctx *context.Context) { } if err := issue.ChangeTitle(ctx.User, title); err != nil { - ctx.Handle(500, "ChangeTitle", err) + ctx.ServerError("ChangeTitle", err) return } @@ -861,7 +861,7 @@ func UpdateIssueContent(ctx *context.Context) { content := ctx.Query("content") if err := issue.ChangeContent(ctx.User, content); err != nil { - ctx.Handle(500, "ChangeContent", err) + ctx.ServerError("ChangeContent", err) return } @@ -885,7 +885,7 @@ func UpdateIssueMilestone(ctx *context.Context) { } issue.MilestoneID = milestoneID if err := models.ChangeMilestoneAssign(issue, ctx.User, oldMilestoneID); err != nil { - ctx.Handle(500, "ChangeMilestoneAssign", err) + ctx.ServerError("ChangeMilestoneAssign", err) return } } @@ -908,7 +908,7 @@ func UpdateIssueAssignee(ctx *context.Context) { continue } if err := issue.ChangeAssignee(ctx.User, assigneeID); err != nil { - ctx.Handle(500, "ChangeAssignee", err) + ctx.ServerError("ChangeAssignee", err) return } } @@ -935,12 +935,12 @@ func UpdateIssueStatus(ctx *context.Context) { } if _, err := models.IssueList(issues).LoadRepositories(); err != nil { - ctx.Handle(500, "LoadRepositories", err) + ctx.ServerError("LoadRepositories", err) return } for _, issue := range issues { if err := issue.ChangeStatus(ctx.User, issue.Repo, isClosed); err != nil { - ctx.Handle(500, "ChangeStatus", err) + ctx.ServerError("ChangeStatus", err) return } } @@ -982,7 +982,7 @@ func NewComment(ctx *context.Context, form auth.CreateCommentForm) { pr, err := models.GetUnmergedPullRequest(pull.HeadRepoID, pull.BaseRepoID, pull.HeadBranch, pull.BaseBranch) if err != nil { if !models.IsErrPullRequestNotExist(err) { - ctx.Handle(500, "GetUnmergedPullRequest", err) + ctx.ServerError("GetUnmergedPullRequest", err) return } } @@ -990,7 +990,7 @@ func NewComment(ctx *context.Context, form auth.CreateCommentForm) { // Regenerate patch and test conflict. if pr == nil { if err = issue.PullRequest.UpdatePatch(); err != nil { - ctx.Handle(500, "UpdatePatch", err) + ctx.ServerError("UpdatePatch", err) return } @@ -1030,7 +1030,7 @@ func NewComment(ctx *context.Context, form auth.CreateCommentForm) { comment, err := models.CreateIssueComment(ctx.User, ctx.Repo.Repository, issue, form.Content, attachments) if err != nil { - ctx.Handle(500, "CreateIssueComment", err) + ctx.ServerError("CreateIssueComment", err) return } @@ -1063,7 +1063,7 @@ func UpdateCommentContent(ctx *context.Context) { return } if err = models.UpdateComment(comment); err != nil { - ctx.Handle(500, "UpdateComment", err) + ctx.ServerError("UpdateComment", err) return } @@ -1089,7 +1089,7 @@ func DeleteComment(ctx *context.Context) { } if err = models.DeleteComment(comment); err != nil { - ctx.Handle(500, "DeleteCommentByID", err) + ctx.ServerError("DeleteCommentByID", err) return } @@ -1105,7 +1105,7 @@ func Milestones(ctx *context.Context) { isShowClosed := ctx.Query("state") == "closed" openCount, closedCount, err := models.MilestoneStats(ctx.Repo.Repository.ID) if err != nil { - ctx.Handle(500, "MilestoneStats", err) + ctx.ServerError("MilestoneStats", err) return } ctx.Data["OpenCount"] = openCount @@ -1127,7 +1127,7 @@ func Milestones(ctx *context.Context) { miles, err := models.GetMilestones(ctx.Repo.Repository.ID, page, isShowClosed, sortType) if err != nil { - ctx.Handle(500, "GetMilestones", err) + ctx.ServerError("GetMilestones", err) return } for _, m := range miles { @@ -1185,7 +1185,7 @@ func NewMilestonePost(ctx *context.Context, form auth.CreateMilestoneForm) { Content: form.Content, DeadlineUnix: util.TimeStamp(deadline.Unix()), }); err != nil { - ctx.Handle(500, "NewMilestone", err) + ctx.ServerError("NewMilestone", err) return } @@ -1204,9 +1204,9 @@ func EditMilestone(ctx *context.Context) { m, err := models.GetMilestoneByRepoID(ctx.Repo.Repository.ID, ctx.ParamsInt64(":id")) if err != nil { if models.IsErrMilestoneNotExist(err) { - ctx.Handle(404, "", nil) + ctx.NotFound("", nil) } else { - ctx.Handle(500, "GetMilestoneByRepoID", err) + ctx.ServerError("GetMilestoneByRepoID", err) } return } @@ -1244,9 +1244,9 @@ func EditMilestonePost(ctx *context.Context, form auth.CreateMilestoneForm) { m, err := models.GetMilestoneByRepoID(ctx.Repo.Repository.ID, ctx.ParamsInt64(":id")) if err != nil { if models.IsErrMilestoneNotExist(err) { - ctx.Handle(404, "", nil) + ctx.NotFound("", nil) } else { - ctx.Handle(500, "GetMilestoneByRepoID", err) + ctx.ServerError("GetMilestoneByRepoID", err) } return } @@ -1254,7 +1254,7 @@ func EditMilestonePost(ctx *context.Context, form auth.CreateMilestoneForm) { m.Content = form.Content m.DeadlineUnix = util.TimeStamp(deadline.Unix()) if err = models.UpdateMilestone(m); err != nil { - ctx.Handle(500, "UpdateMilestone", err) + ctx.ServerError("UpdateMilestone", err) return } @@ -1267,9 +1267,9 @@ func ChangeMilestonStatus(ctx *context.Context) { m, err := models.GetMilestoneByRepoID(ctx.Repo.Repository.ID, ctx.ParamsInt64(":id")) if err != nil { if models.IsErrMilestoneNotExist(err) { - ctx.Handle(404, "", err) + ctx.NotFound("", err) } else { - ctx.Handle(500, "GetMilestoneByRepoID", err) + ctx.ServerError("GetMilestoneByRepoID", err) } return } @@ -1278,7 +1278,7 @@ func ChangeMilestonStatus(ctx *context.Context) { case "open": if m.IsClosed { if err = models.ChangeMilestoneStatus(m, false); err != nil { - ctx.Handle(500, "ChangeMilestoneStatus", err) + ctx.ServerError("ChangeMilestoneStatus", err) return } } @@ -1287,7 +1287,7 @@ func ChangeMilestonStatus(ctx *context.Context) { if !m.IsClosed { m.ClosedDateUnix = util.TimeStampNow() if err = models.ChangeMilestoneStatus(m, true); err != nil { - ctx.Handle(500, "ChangeMilestoneStatus", err) + ctx.ServerError("ChangeMilestoneStatus", err) return } } @@ -1318,7 +1318,7 @@ func ChangeIssueReaction(ctx *context.Context, form auth.ReactionForm) { } if ctx.HasError() { - ctx.Handle(500, "ChangeIssueReaction", errors.New(ctx.GetErrMsg())) + ctx.ServerError("ChangeIssueReaction", errors.New(ctx.GetErrMsg())) return } @@ -1339,7 +1339,7 @@ func ChangeIssueReaction(ctx *context.Context, form auth.ReactionForm) { log.Trace("Reaction for issue created: %d/%d/%d", ctx.Repo.Repository.ID, issue.ID, reaction.ID) case "unreact": if err := models.DeleteIssueReaction(ctx.User, issue, form.Content); err != nil { - ctx.Handle(500, "DeleteIssueReaction", err) + ctx.ServerError("DeleteIssueReaction", err) return } @@ -1352,7 +1352,7 @@ func ChangeIssueReaction(ctx *context.Context, form auth.ReactionForm) { log.Trace("Reaction for issue removed: %d/%d", ctx.Repo.Repository.ID, issue.ID) default: - ctx.Handle(404, fmt.Sprintf("Unknown action %s", ctx.Params(":action")), nil) + ctx.NotFound(fmt.Sprintf("Unknown action %s", ctx.Params(":action")), nil) return } @@ -1370,7 +1370,7 @@ func ChangeIssueReaction(ctx *context.Context, form auth.ReactionForm) { "Reactions": issue.Reactions.GroupByType(), }) if err != nil { - ctx.Handle(500, "ChangeIssueReaction.HTMLString", err) + ctx.ServerError("ChangeIssueReaction.HTMLString", err) return } ctx.JSON(200, map[string]interface{}{ @@ -1393,7 +1393,7 @@ func ChangeCommentReaction(ctx *context.Context, form auth.ReactionForm) { } if ctx.HasError() { - ctx.Handle(500, "ChangeCommentReaction", errors.New(ctx.GetErrMsg())) + ctx.ServerError("ChangeCommentReaction", errors.New(ctx.GetErrMsg())) return } @@ -1414,7 +1414,7 @@ func ChangeCommentReaction(ctx *context.Context, form auth.ReactionForm) { log.Trace("Reaction for comment created: %d/%d/%d/%d", ctx.Repo.Repository.ID, issue.ID, comment.ID, reaction.ID) case "unreact": if err := models.DeleteCommentReaction(ctx.User, issue, comment, form.Content); err != nil { - ctx.Handle(500, "DeleteCommentReaction", err) + ctx.ServerError("DeleteCommentReaction", err) return } @@ -1427,7 +1427,7 @@ func ChangeCommentReaction(ctx *context.Context, form auth.ReactionForm) { log.Trace("Reaction for comment removed: %d/%d/%d", ctx.Repo.Repository.ID, issue.ID, comment.ID) default: - ctx.Handle(404, fmt.Sprintf("Unknown action %s", ctx.Params(":action")), nil) + ctx.NotFound(fmt.Sprintf("Unknown action %s", ctx.Params(":action")), nil) return } @@ -1445,7 +1445,7 @@ func ChangeCommentReaction(ctx *context.Context, form auth.ReactionForm) { "Reactions": comment.Reactions.GroupByType(), }) if err != nil { - ctx.Handle(500, "ChangeCommentReaction.HTMLString", err) + ctx.ServerError("ChangeCommentReaction.HTMLString", err) return } ctx.JSON(200, map[string]interface{}{ diff --git a/routers/repo/issue_label.go b/routers/repo/issue_label.go index f8a955ba6d..a197256be8 100644 --- a/routers/repo/issue_label.go +++ b/routers/repo/issue_label.go @@ -48,7 +48,7 @@ func InitializeLabels(ctx *context.Context, form auth.InitializeLabelsForm) { } } if err := models.NewLabels(labels...); err != nil { - ctx.Handle(500, "NewLabels", err) + ctx.ServerError("NewLabels", err) return } ctx.Redirect(ctx.Repo.RepoLink + "/labels") @@ -58,7 +58,7 @@ func InitializeLabels(ctx *context.Context, form auth.InitializeLabelsForm) { func RetrieveLabels(ctx *context.Context) { labels, err := models.GetLabelsByRepoID(ctx.Repo.Repository.ID, ctx.Query("sort")) if err != nil { - ctx.Handle(500, "RetrieveLabels.GetLabels", err) + ctx.ServerError("RetrieveLabels.GetLabels", err) return } for _, l := range labels { @@ -86,7 +86,7 @@ func NewLabel(ctx *context.Context, form auth.CreateLabelForm) { Color: form.Color, } if err := models.NewLabel(l); err != nil { - ctx.Handle(500, "NewLabel", err) + ctx.ServerError("NewLabel", err) return } ctx.Redirect(ctx.Repo.RepoLink + "/labels") @@ -100,7 +100,7 @@ func UpdateLabel(ctx *context.Context, form auth.CreateLabelForm) { case models.IsErrLabelNotExist(err): ctx.Error(404) default: - ctx.Handle(500, "UpdateLabel", err) + ctx.ServerError("UpdateLabel", err) } return } @@ -108,7 +108,7 @@ func UpdateLabel(ctx *context.Context, form auth.CreateLabelForm) { l.Name = form.Title l.Color = form.Color if err := models.UpdateLabel(l); err != nil { - ctx.Handle(500, "UpdateLabel", err) + ctx.ServerError("UpdateLabel", err) return } ctx.Redirect(ctx.Repo.RepoLink + "/labels") @@ -139,7 +139,7 @@ func UpdateIssueLabel(ctx *context.Context) { case "clear": for _, issue := range issues { if err := issue.ClearLabels(ctx.User); err != nil { - ctx.Handle(500, "ClearLabels", err) + ctx.ServerError("ClearLabels", err) return } } @@ -149,7 +149,7 @@ func UpdateIssueLabel(ctx *context.Context) { if models.IsErrLabelNotExist(err) { ctx.Error(404, "GetLabelByID") } else { - ctx.Handle(500, "GetLabelByID", err) + ctx.ServerError("GetLabelByID", err) } return } @@ -168,14 +168,14 @@ func UpdateIssueLabel(ctx *context.Context) { if action == "attach" { for _, issue := range issues { if err = issue.AddLabel(ctx.User, label); err != nil { - ctx.Handle(500, "AddLabel", err) + ctx.ServerError("AddLabel", err) return } } } else { for _, issue := range issues { if err = issue.RemoveLabel(ctx.User, label); err != nil { - ctx.Handle(500, "RemoveLabel", err) + ctx.ServerError("RemoveLabel", err) return } } diff --git a/routers/repo/issue_stopwatch.go b/routers/repo/issue_stopwatch.go index f4392849aa..a7d6ed39cc 100644 --- a/routers/repo/issue_stopwatch.go +++ b/routers/repo/issue_stopwatch.go @@ -18,12 +18,12 @@ func IssueStopwatch(c *context.Context) { return } if !c.Repo.CanUseTimetracker(issue, c.User) { - c.Handle(http.StatusNotFound, "CanUseTimetracker", nil) + c.NotFound("CanUseTimetracker", nil) return } if err := models.CreateOrStopIssueStopwatch(c.User, issue); err != nil { - c.Handle(http.StatusInternalServerError, "CreateOrStopIssueStopwatch", err) + c.ServerError("CreateOrStopIssueStopwatch", err) return } @@ -38,12 +38,12 @@ func CancelStopwatch(c *context.Context) { return } if !c.Repo.CanUseTimetracker(issue, c.User) { - c.Handle(http.StatusNotFound, "CanUseTimetracker", nil) + c.NotFound("CanUseTimetracker", nil) return } if err := models.CancelStopwatch(c.User, issue); err != nil { - c.Handle(http.StatusInternalServerError, "CancelStopwatch", err) + c.ServerError("CancelStopwatch", err) return } diff --git a/routers/repo/issue_timetrack.go b/routers/repo/issue_timetrack.go index d89c67b497..05cf137931 100644 --- a/routers/repo/issue_timetrack.go +++ b/routers/repo/issue_timetrack.go @@ -20,7 +20,7 @@ func AddTimeManually(c *context.Context, form auth.AddTimeManuallyForm) { return } if !c.Repo.CanUseTimetracker(issue, c.User) { - c.Handle(http.StatusNotFound, "CanUseTimetracker", nil) + c.NotFound("CanUseTimetracker", nil) return } url := issue.HTMLURL() @@ -40,7 +40,7 @@ func AddTimeManually(c *context.Context, form auth.AddTimeManuallyForm) { } if _, err := models.AddTime(c.User, issue, int64(total.Seconds())); err != nil { - c.Handle(http.StatusInternalServerError, "AddTime", err) + c.ServerError("AddTime", err) return } diff --git a/routers/repo/issue_watch.go b/routers/repo/issue_watch.go index 42ffaec5b8..a499b70d9c 100644 --- a/routers/repo/issue_watch.go +++ b/routers/repo/issue_watch.go @@ -17,7 +17,7 @@ import ( func IssueWatch(c *context.Context) { watch, err := strconv.ParseBool(c.Req.PostForm.Get("watch")) if err != nil { - c.Handle(http.StatusInternalServerError, "watch is not bool", err) + c.ServerError("watch is not bool", err) return } @@ -27,7 +27,7 @@ func IssueWatch(c *context.Context) { } if err := models.CreateOrUpdateIssueWatch(c.User.ID, issue.ID, watch); err != nil { - c.Handle(http.StatusInternalServerError, "CreateOrUpdateIssueWatch", err) + c.ServerError("CreateOrUpdateIssueWatch", err) return } diff --git a/routers/repo/middlewares.go b/routers/repo/middlewares.go index 1829e0d491..8afad5be64 100644 --- a/routers/repo/middlewares.go +++ b/routers/repo/middlewares.go @@ -15,7 +15,7 @@ func SetEditorconfigIfExists(ctx *context.Context) { if err != nil && !git.IsErrNotExist(err) { description := fmt.Sprintf("Error while getting .editorconfig file: %v", err) if err := models.CreateRepositoryNotice(description); err != nil { - ctx.Handle(500, "ErrCreatingReporitoryNotice", err) + ctx.ServerError("ErrCreatingReporitoryNotice", err) } return } @@ -47,6 +47,6 @@ func SetDiffViewStyle(ctx *context.Context) { ctx.Data["IsSplitStyle"] = style == "split" if err := ctx.User.UpdateDiffViewStyle(style); err != nil { - ctx.Handle(500, "ErrUpdateDiffViewStyle", err) + ctx.ServerError("ErrUpdateDiffViewStyle", err) } } diff --git a/routers/repo/pull.go b/routers/repo/pull.go index 35b5b0be2b..c06c67552f 100644 --- a/routers/repo/pull.go +++ b/routers/repo/pull.go @@ -50,15 +50,15 @@ func getForkRepository(ctx *context.Context) *models.Repository { forkRepo, err := models.GetRepositoryByID(ctx.ParamsInt64(":repoid")) if err != nil { if models.IsErrRepoNotExist(err) { - ctx.Handle(404, "GetRepositoryByID", nil) + ctx.NotFound("GetRepositoryByID", nil) } else { - ctx.Handle(500, "GetRepositoryByID", err) + ctx.ServerError("GetRepositoryByID", err) } return nil } if !forkRepo.CanBeForked() || !forkRepo.HasAccess(ctx.User) { - ctx.Handle(404, "getForkRepository", nil) + ctx.NotFound("getForkRepository", nil) return nil } @@ -68,14 +68,14 @@ func getForkRepository(ctx *context.Context) *models.Repository { canForkToUser := forkRepo.OwnerID != ctx.User.ID && !ctx.User.HasForkedRepo(forkRepo.ID) if err = forkRepo.GetOwner(); err != nil { - ctx.Handle(500, "GetOwner", err) + ctx.ServerError("GetOwner", err) return nil } ctx.Data["ForkFrom"] = forkRepo.Owner.Name + "/" + forkRepo.Name ctx.Data["ForkFromOwnerID"] = forkRepo.Owner.ID if err := ctx.User.GetOwnedOrganizations(); err != nil { - ctx.Handle(500, "GetOwnedOrganizations", err) + ctx.ServerError("GetOwnedOrganizations", err) return nil } var orgs []*models.User @@ -103,7 +103,7 @@ func getForkRepository(ctx *context.Context) *models.Repository { } traverseParentRepo, err = models.GetRepositoryByID(traverseParentRepo.ForkID) if err != nil { - ctx.Handle(500, "GetRepositoryByID", err) + ctx.ServerError("GetRepositoryByID", err) return nil } } @@ -170,7 +170,7 @@ func ForkPost(ctx *context.Context, form auth.CreateRepoForm) { } traverseParentRepo, err = models.GetRepositoryByID(traverseParentRepo.ForkID) if err != nil { - ctx.Handle(500, "GetRepositoryByID", err) + ctx.ServerError("GetRepositoryByID", err) return } } @@ -179,7 +179,7 @@ func ForkPost(ctx *context.Context, form auth.CreateRepoForm) { if ctxUser.IsOrganization() { isOwner, err := ctxUser.IsOwnedBy(ctx.User.ID) if err != nil { - ctx.Handle(500, "IsOwnedBy", err) + ctx.ServerError("IsOwnedBy", err) return } else if !isOwner { ctx.Error(403) @@ -198,7 +198,7 @@ func ForkPost(ctx *context.Context, form auth.CreateRepoForm) { case models.IsErrNamePatternNotAllowed(err): ctx.RenderWithErr(ctx.Tr("repo.form.name_pattern_not_allowed", err.(models.ErrNamePatternNotAllowed).Pattern), tplFork, &form) default: - ctx.Handle(500, "ForkPost", err) + ctx.ServerError("ForkPost", err) } return } @@ -211,9 +211,9 @@ func checkPullInfo(ctx *context.Context) *models.Issue { issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index")) if err != nil { if models.IsErrIssueNotExist(err) { - ctx.Handle(404, "GetIssueByIndex", err) + ctx.NotFound("GetIssueByIndex", err) } else { - ctx.Handle(500, "GetIssueByIndex", err) + ctx.ServerError("GetIssueByIndex", err) } return nil } @@ -221,19 +221,19 @@ func checkPullInfo(ctx *context.Context) *models.Issue { ctx.Data["Issue"] = issue if !issue.IsPull { - ctx.Handle(404, "ViewPullCommits", nil) + ctx.NotFound("ViewPullCommits", nil) return nil } if err = issue.PullRequest.GetHeadRepo(); err != nil { - ctx.Handle(500, "GetHeadRepo", err) + ctx.ServerError("GetHeadRepo", err) return nil } if ctx.IsSigned { // Update issue-user. if err = issue.ReadBy(ctx.User.ID); err != nil { - ctx.Handle(500, "ReadBy", err) + ctx.ServerError("ReadBy", err) return nil } } @@ -258,7 +258,7 @@ func PrepareMergedViewPullInfo(ctx *context.Context, issue *models.Issue) { var err error if err = pull.GetHeadRepo(); err != nil { - ctx.Handle(500, "GetHeadRepo", err) + ctx.ServerError("GetHeadRepo", err) return } @@ -267,24 +267,24 @@ func PrepareMergedViewPullInfo(ctx *context.Context, issue *models.Issue) { mergedCommit, err := ctx.Repo.GitRepo.GetCommit(pull.MergedCommitID) if err != nil { - ctx.Handle(500, "GetCommit", err) + ctx.ServerError("GetCommit", err) return } // the ID of the last commit in the PR (not including the merge commit) endCommitID, err := mergedCommit.ParentID(mergedCommit.ParentCount() - 1) if err != nil { - ctx.Handle(500, "ParentID", err) + ctx.ServerError("ParentID", err) return } ctx.Data["NumCommits"], err = ctx.Repo.GitRepo.CommitsCountBetween(pull.MergeBase, endCommitID.String()) if err != nil { - ctx.Handle(500, "Repo.GitRepo.CommitsCountBetween", err) + ctx.ServerError("Repo.GitRepo.CommitsCountBetween", err) return } ctx.Data["NumFiles"], err = ctx.Repo.GitRepo.FilesCountBetween(pull.MergeBase, endCommitID.String()) if err != nil { - ctx.Handle(500, "Repo.GitRepo.FilesCountBetween", err) + ctx.ServerError("Repo.GitRepo.FilesCountBetween", err) return } } @@ -296,7 +296,7 @@ func PrepareViewPullInfo(ctx *context.Context, issue *models.Issue) *git.PullReq var err error if err = pull.GetHeadRepo(); err != nil { - ctx.Handle(500, "GetHeadRepo", err) + ctx.ServerError("GetHeadRepo", err) return nil } @@ -306,7 +306,7 @@ func PrepareViewPullInfo(ctx *context.Context, issue *models.Issue) *git.PullReq if pull.HeadRepo != nil { headGitRepo, err = git.OpenRepository(pull.HeadRepo.RepoPath()) if err != nil { - ctx.Handle(500, "OpenRepository", err) + ctx.ServerError("OpenRepository", err) return nil } } @@ -330,7 +330,7 @@ func PrepareViewPullInfo(ctx *context.Context, issue *models.Issue) *git.PullReq return nil } - ctx.Handle(500, "GetPullRequestInfo", err) + ctx.ServerError("GetPullRequestInfo", err) return nil } ctx.Data["NumCommits"] = prInfo.Commits.Len() @@ -360,17 +360,17 @@ func ViewPullCommits(ctx *context.Context) { mergedCommit, err := ctx.Repo.GitRepo.GetCommit(pull.MergedCommitID) if err != nil { - ctx.Handle(500, "Repo.GitRepo.GetCommit", err) + ctx.ServerError("Repo.GitRepo.GetCommit", err) return } endCommitID, err := mergedCommit.ParentID(mergedCommit.ParentCount() - 1) if err != nil { - ctx.Handle(500, "ParentID", err) + ctx.ServerError("ParentID", err) return } commits, err = ctx.Repo.GitRepo.CommitsBetweenIDs(endCommitID.String(), pull.MergeBase) if err != nil { - ctx.Handle(500, "Repo.GitRepo.CommitsBetweenIDs", err) + ctx.ServerError("Repo.GitRepo.CommitsBetweenIDs", err) return } } else { @@ -378,7 +378,7 @@ func ViewPullCommits(ctx *context.Context) { if ctx.Written() { return } else if prInfo == nil { - ctx.Handle(404, "ViewPullCommits", nil) + ctx.NotFound("ViewPullCommits", nil) return } ctx.Data["Username"] = pull.HeadUserName @@ -424,12 +424,12 @@ func ViewPullFiles(ctx *context.Context) { startCommitID = pull.MergeBase mergedCommit, err := ctx.Repo.GitRepo.GetCommit(pull.MergedCommitID) if err != nil { - ctx.Handle(500, "GetCommit", err) + ctx.ServerError("GetCommit", err) return } endCommitSha, err := mergedCommit.ParentID(mergedCommit.ParentCount() - 1) if err != nil { - ctx.Handle(500, "ParentID", err) + ctx.ServerError("ParentID", err) return } endCommitID = endCommitSha.String() @@ -443,7 +443,7 @@ func ViewPullFiles(ctx *context.Context) { if ctx.Written() { return } else if prInfo == nil { - ctx.Handle(404, "ViewPullFiles", nil) + ctx.NotFound("ViewPullFiles", nil) return } @@ -451,13 +451,13 @@ func ViewPullFiles(ctx *context.Context) { headGitRepo, err := git.OpenRepository(headRepoPath) if err != nil { - ctx.Handle(500, "OpenRepository", err) + ctx.ServerError("OpenRepository", err) return } headCommitID, err := headGitRepo.GetBranchCommitID(pull.HeadBranch) if err != nil { - ctx.Handle(500, "GetBranchCommitID", err) + ctx.ServerError("GetBranchCommitID", err) return } @@ -475,7 +475,7 @@ func ViewPullFiles(ctx *context.Context) { startCommitID, endCommitID, setting.Git.MaxGitDiffLines, setting.Git.MaxGitDiffLineCharacters, setting.Git.MaxGitDiffFiles) if err != nil { - ctx.Handle(500, "GetDiffRange", err) + ctx.ServerError("GetDiffRange", err) return } ctx.Data["Diff"] = diff @@ -483,7 +483,7 @@ func ViewPullFiles(ctx *context.Context) { commit, err := gitRepo.GetCommit(endCommitID) if err != nil { - ctx.Handle(500, "GetCommit", err) + ctx.ServerError("GetCommit", err) return } @@ -503,23 +503,23 @@ func MergePullRequest(ctx *context.Context, form auth.MergePullRequestForm) { return } if issue.IsClosed { - ctx.Handle(404, "MergePullRequest", nil) + ctx.NotFound("MergePullRequest", nil) return } pr, err := models.GetPullRequestByIssueID(issue.ID) if err != nil { if models.IsErrPullRequestNotExist(err) { - ctx.Handle(404, "GetPullRequestByIssueID", nil) + ctx.NotFound("GetPullRequestByIssueID", nil) } else { - ctx.Handle(500, "GetPullRequestByIssueID", err) + ctx.ServerError("GetPullRequestByIssueID", err) } return } pr.Issue = issue if !pr.CanAutoMerge() || pr.HasMerged { - ctx.Handle(404, "MergePullRequest", nil) + ctx.NotFound("MergePullRequest", nil) return } @@ -552,7 +552,7 @@ func MergePullRequest(ctx *context.Context, form auth.MergePullRequestForm) { ctx.Redirect(ctx.Repo.RepoLink + "/pulls/" + com.ToStr(pr.Index)) return } - ctx.Handle(500, "Merge", err) + ctx.ServerError("Merge", err) return } @@ -580,12 +580,12 @@ func ParseCompareInfo(ctx *context.Context) (*models.User, *models.Repository, * ) infoPath, err = url.QueryUnescape(ctx.Params("*")) if err != nil { - ctx.Handle(404, "QueryUnescape", err) + ctx.NotFound("QueryUnescape", err) } infos := strings.Split(infoPath, "...") if len(infos) != 2 { log.Trace("ParseCompareInfo[%d]: not enough compared branches information %s", baseRepo.ID, infos) - ctx.Handle(404, "CompareAndPullRequest", nil) + ctx.NotFound("CompareAndPullRequest", nil) return nil, nil, nil, nil, "", "" } @@ -603,16 +603,16 @@ func ParseCompareInfo(ctx *context.Context) (*models.User, *models.Repository, * headUser, err = models.GetUserByName(headInfos[0]) if err != nil { if models.IsErrUserNotExist(err) { - ctx.Handle(404, "GetUserByName", nil) + ctx.NotFound("GetUserByName", nil) } else { - ctx.Handle(500, "GetUserByName", err) + ctx.ServerError("GetUserByName", err) } return nil, nil, nil, nil, "", "" } headBranch = headInfos[1] isSameRepo = headUser.ID == ctx.Repo.Owner.ID } else { - ctx.Handle(404, "CompareAndPullRequest", nil) + ctx.NotFound("CompareAndPullRequest", nil) return nil, nil, nil, nil, "", "" } ctx.Data["HeadUser"] = headUser @@ -621,7 +621,7 @@ func ParseCompareInfo(ctx *context.Context) (*models.User, *models.Repository, * // Check if base branch is valid. if !ctx.Repo.GitRepo.IsBranchExist(baseBranch) { - ctx.Handle(404, "IsBranchExist", nil) + ctx.NotFound("IsBranchExist", nil) return nil, nil, nil, nil, "", "" } @@ -629,7 +629,7 @@ func ParseCompareInfo(ctx *context.Context) (*models.User, *models.Repository, * headRepo, has := models.HasForkedRepo(headUser.ID, baseRepo.ID) if !has && !isSameRepo { log.Trace("ParseCompareInfo[%d]: does not have fork or in same repository", baseRepo.ID) - ctx.Handle(404, "ParseCompareInfo", nil) + ctx.NotFound("ParseCompareInfo", nil) return nil, nil, nil, nil, "", "" } @@ -640,33 +640,33 @@ func ParseCompareInfo(ctx *context.Context) (*models.User, *models.Repository, * } else { headGitRepo, err = git.OpenRepository(models.RepoPath(headUser.Name, headRepo.Name)) if err != nil { - ctx.Handle(500, "OpenRepository", err) + ctx.ServerError("OpenRepository", err) return nil, nil, nil, nil, "", "" } } if !ctx.User.IsWriterOfRepo(headRepo) && !ctx.User.IsAdmin { log.Trace("ParseCompareInfo[%d]: does not have write access or site admin", baseRepo.ID) - ctx.Handle(404, "ParseCompareInfo", nil) + ctx.NotFound("ParseCompareInfo", nil) return nil, nil, nil, nil, "", "" } // Check if head branch is valid. if !headGitRepo.IsBranchExist(headBranch) { - ctx.Handle(404, "IsBranchExist", nil) + ctx.NotFound("IsBranchExist", nil) return nil, nil, nil, nil, "", "" } headBranches, err := headGitRepo.GetBranches() if err != nil { - ctx.Handle(500, "GetBranches", err) + ctx.ServerError("GetBranches", err) return nil, nil, nil, nil, "", "" } ctx.Data["HeadBranches"] = headBranches prInfo, err := headGitRepo.GetPullRequestInfo(models.RepoPath(baseRepo.Owner.Name, baseRepo.Name), baseBranch, headBranch) if err != nil { - ctx.Handle(500, "GetPullRequestInfo", err) + ctx.ServerError("GetPullRequestInfo", err) return nil, nil, nil, nil, "", "" } ctx.Data["BeforeCommitID"] = prInfo.MergeBase @@ -693,7 +693,7 @@ func PrepareCompareDiff( headCommitID, err := headGitRepo.GetBranchCommitID(headBranch) if err != nil { - ctx.Handle(500, "GetBranchCommitID", err) + ctx.ServerError("GetBranchCommitID", err) return false } ctx.Data["AfterCommitID"] = headCommitID @@ -707,7 +707,7 @@ func PrepareCompareDiff( prInfo.MergeBase, headCommitID, setting.Git.MaxGitDiffLines, setting.Git.MaxGitDiffLineCharacters, setting.Git.MaxGitDiffFiles) if err != nil { - ctx.Handle(500, "GetDiffRange", err) + ctx.ServerError("GetDiffRange", err) return false } ctx.Data["Diff"] = diff @@ -715,7 +715,7 @@ func PrepareCompareDiff( headCommit, err := headGitRepo.GetCommit(headCommitID) if err != nil { - ctx.Handle(500, "GetCommit", err) + ctx.ServerError("GetCommit", err) return false } @@ -753,7 +753,7 @@ func CompareAndPullRequest(ctx *context.Context) { pr, err := models.GetUnmergedPullRequest(headRepo.ID, ctx.Repo.Repository.ID, headBranch, baseBranch) if err != nil { if !models.IsErrPullRequestNotExist(err) { - ctx.Handle(500, "GetUnmergedPullRequest", err) + ctx.ServerError("GetUnmergedPullRequest", err) return } } else { @@ -822,7 +822,7 @@ func CompareAndPullRequestPost(ctx *context.Context, form auth.CreateIssueForm) patch, err := headGitRepo.GetPatch(prInfo.MergeBase, headBranch) if err != nil { - ctx.Handle(500, "GetPatch", err) + ctx.ServerError("GetPatch", err) return } @@ -851,10 +851,10 @@ func CompareAndPullRequestPost(ctx *context.Context, form auth.CreateIssueForm) // FIXME: check error in the case two people send pull request at almost same time, give nice error prompt // instead of 500. if err := models.NewPullRequest(repo, pullIssue, labelIDs, attachments, pullRequest, patch); err != nil { - ctx.Handle(500, "NewPullRequest", err) + ctx.ServerError("NewPullRequest", err) return } else if err := pullRequest.PushToBaseRepo(); err != nil { - ctx.Handle(500, "PushToBaseRepo", err) + ctx.ServerError("PushToBaseRepo", err) return } @@ -889,7 +889,7 @@ func TriggerTask(ctx *context.Context) { if models.IsErrUserNotExist(err) { ctx.Error(404) } else { - ctx.Handle(500, "GetUserByID", err) + ctx.ServerError("GetUserByID", err) } return } @@ -911,36 +911,36 @@ func CleanUpPullRequest(ctx *context.Context) { pr, err := models.GetPullRequestByIssueID(issue.ID) if err != nil { if models.IsErrPullRequestNotExist(err) { - ctx.Handle(404, "GetPullRequestByIssueID", nil) + ctx.NotFound("GetPullRequestByIssueID", nil) } else { - ctx.Handle(500, "GetPullRequestByIssueID", err) + ctx.ServerError("GetPullRequestByIssueID", err) } return } // Allow cleanup only for merged PR if !pr.HasMerged { - ctx.Handle(404, "CleanUpPullRequest", nil) + ctx.NotFound("CleanUpPullRequest", nil) return } if err = pr.GetHeadRepo(); err != nil { - ctx.Handle(500, "GetHeadRepo", err) + ctx.ServerError("GetHeadRepo", err) return } else if pr.HeadRepo == nil { // Forked repository has already been deleted - ctx.Handle(404, "CleanUpPullRequest", nil) + ctx.NotFound("CleanUpPullRequest", nil) return } else if pr.GetBaseRepo(); err != nil { - ctx.Handle(500, "GetBaseRepo", err) + ctx.ServerError("GetBaseRepo", err) return } else if pr.HeadRepo.GetOwner(); err != nil { - ctx.Handle(500, "HeadRepo.GetOwner", err) + ctx.ServerError("HeadRepo.GetOwner", err) return } if !ctx.User.IsWriterOfRepo(pr.HeadRepo) { - ctx.Handle(403, "CleanUpPullRequest", nil) + ctx.NotFound("CleanUpPullRequest", nil) return } @@ -948,13 +948,13 @@ func CleanUpPullRequest(ctx *context.Context) { gitRepo, err := git.OpenRepository(pr.HeadRepo.RepoPath()) if err != nil { - ctx.Handle(500, fmt.Sprintf("OpenRepository[%s]", pr.HeadRepo.RepoPath()), err) + ctx.ServerError(fmt.Sprintf("OpenRepository[%s]", pr.HeadRepo.RepoPath()), err) return } gitBaseRepo, err := git.OpenRepository(pr.BaseRepo.RepoPath()) if err != nil { - ctx.Handle(500, fmt.Sprintf("OpenRepository[%s]", pr.BaseRepo.RepoPath()), err) + ctx.ServerError(fmt.Sprintf("OpenRepository[%s]", pr.BaseRepo.RepoPath()), err) return } @@ -1033,16 +1033,16 @@ func DownloadPullDiff(ctx *context.Context) { issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index")) if err != nil { if models.IsErrIssueNotExist(err) { - ctx.Handle(404, "GetIssueByIndex", err) + ctx.NotFound("GetIssueByIndex", err) } else { - ctx.Handle(500, "GetIssueByIndex", err) + ctx.ServerError("GetIssueByIndex", err) } return } // Return not found if it's not a pull request if !issue.IsPull { - ctx.Handle(404, "DownloadPullDiff", + ctx.NotFound("DownloadPullDiff", fmt.Errorf("Issue is not a pull request")) return } @@ -1050,12 +1050,12 @@ func DownloadPullDiff(ctx *context.Context) { pr := issue.PullRequest if err = pr.GetBaseRepo(); err != nil { - ctx.Handle(500, "GetBaseRepo", err) + ctx.ServerError("GetBaseRepo", err) return } patch, err := pr.BaseRepo.PatchPath(pr.Index) if err != nil { - ctx.Handle(500, "PatchPath", err) + ctx.ServerError("PatchPath", err) return } @@ -1067,16 +1067,16 @@ func DownloadPullPatch(ctx *context.Context) { issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index")) if err != nil { if models.IsErrIssueNotExist(err) { - ctx.Handle(404, "GetIssueByIndex", err) + ctx.NotFound("GetIssueByIndex", err) } else { - ctx.Handle(500, "GetIssueByIndex", err) + ctx.ServerError("GetIssueByIndex", err) } return } // Return not found if it's not a pull request if !issue.IsPull { - ctx.Handle(404, "DownloadPullDiff", + ctx.NotFound("DownloadPullDiff", fmt.Errorf("Issue is not a pull request")) return } @@ -1084,25 +1084,25 @@ func DownloadPullPatch(ctx *context.Context) { pr := issue.PullRequest if err = pr.GetHeadRepo(); err != nil { - ctx.Handle(500, "GetHeadRepo", err) + ctx.ServerError("GetHeadRepo", err) return } headGitRepo, err := git.OpenRepository(pr.HeadRepo.RepoPath()) if err != nil { - ctx.Handle(500, "OpenRepository", err) + ctx.ServerError("OpenRepository", err) return } patch, err := headGitRepo.GetFormatPatch(pr.MergeBase, pr.HeadBranch) if err != nil { - ctx.Handle(500, "GetFormatPatch", err) + ctx.ServerError("GetFormatPatch", err) return } _, err = io.Copy(ctx, patch) if err != nil { - ctx.Handle(500, "io.Copy", err) + ctx.ServerError("io.Copy", err) return } } diff --git a/routers/repo/release.go b/routers/repo/release.go index a1babbc295..a54576b91b 100644 --- a/routers/repo/release.go +++ b/routers/repo/release.go @@ -72,19 +72,19 @@ func Releases(ctx *context.Context) { releases, err := models.GetReleasesByRepoID(ctx.Repo.Repository.ID, opts, page, limit) if err != nil { - ctx.Handle(500, "GetReleasesByRepoID", err) + ctx.ServerError("GetReleasesByRepoID", err) return } count, err := models.GetReleaseCountByRepoID(ctx.Repo.Repository.ID, opts) if err != nil { - ctx.Handle(500, "GetReleaseCountByRepoID", err) + ctx.ServerError("GetReleaseCountByRepoID", err) return } err = models.GetReleaseAttachments(releases...) if err != nil { - ctx.Handle(500, "GetReleaseAttachments", err) + ctx.ServerError("GetReleaseAttachments", err) return } @@ -103,14 +103,14 @@ func Releases(ctx *context.Context) { if models.IsErrUserNotExist(err) { r.Publisher = models.NewGhostUser() } else { - ctx.Handle(500, "GetUserByID", err) + ctx.ServerError("GetUserByID", err) return } } cacheUsers[r.PublisherID] = r.Publisher } if err := calReleaseNumCommitsBehind(ctx.Repo, r, countCache); err != nil { - ctx.Handle(500, "calReleaseNumCommitsBehind", err) + ctx.ServerError("calReleaseNumCommitsBehind", err) return } r.Note = markdown.RenderString(r.Note, ctx.Repo.RepoLink, ctx.Repo.Repository.ComposeMetas()) @@ -154,7 +154,7 @@ func NewReleasePost(ctx *context.Context, form auth.NewReleaseForm) { rel, err := models.GetRelease(ctx.Repo.Repository.ID, form.TagName) if err != nil { if !models.IsErrReleaseNotExist(err) { - ctx.Handle(500, "GetRelease", err) + ctx.ServerError("GetRelease", err) return } @@ -178,7 +178,7 @@ func NewReleasePost(ctx *context.Context, form auth.NewReleaseForm) { case models.IsErrInvalidTagName(err): ctx.RenderWithErr(ctx.Tr("repo.release.tag_name_invalid"), tplReleaseNew, &form) default: - ctx.Handle(500, "CreateRelease", err) + ctx.ServerError("CreateRelease", err) } return } @@ -199,7 +199,7 @@ func NewReleasePost(ctx *context.Context, form auth.NewReleaseForm) { if err = models.UpdateRelease(ctx.Repo.GitRepo, rel, attachmentUUIDs); err != nil { ctx.Data["Err_TagName"] = true - ctx.Handle(500, "UpdateRelease", err) + ctx.ServerError("UpdateRelease", err) return } } @@ -219,9 +219,9 @@ func EditRelease(ctx *context.Context) { rel, err := models.GetRelease(ctx.Repo.Repository.ID, tagName) if err != nil { if models.IsErrReleaseNotExist(err) { - ctx.Handle(404, "GetRelease", err) + ctx.NotFound("GetRelease", err) } else { - ctx.Handle(500, "GetRelease", err) + ctx.ServerError("GetRelease", err) } return } @@ -246,14 +246,14 @@ func EditReleasePost(ctx *context.Context, form auth.EditReleaseForm) { rel, err := models.GetRelease(ctx.Repo.Repository.ID, tagName) if err != nil { if models.IsErrReleaseNotExist(err) { - ctx.Handle(404, "GetRelease", err) + ctx.NotFound("GetRelease", err) } else { - ctx.Handle(500, "GetRelease", err) + ctx.ServerError("GetRelease", err) } return } if rel.IsTag { - ctx.Handle(404, "GetRelease", err) + ctx.NotFound("GetRelease", err) return } ctx.Data["tag_name"] = rel.TagName @@ -277,7 +277,7 @@ func EditReleasePost(ctx *context.Context, form auth.EditReleaseForm) { rel.IsDraft = len(form.Draft) > 0 rel.IsPrerelease = form.Prerelease if err = models.UpdateRelease(ctx.Repo.GitRepo, rel, attachmentUUIDs); err != nil { - ctx.Handle(500, "UpdateRelease", err) + ctx.ServerError("UpdateRelease", err) return } ctx.Redirect(ctx.Repo.RepoLink + "/releases") diff --git a/routers/repo/repo.go b/routers/repo/repo.go index 4cd7c8062c..20ea1e24a2 100644 --- a/routers/repo/repo.go +++ b/routers/repo/repo.go @@ -31,14 +31,14 @@ const ( // MustBeNotBare render when a repo is a bare git dir func MustBeNotBare(ctx *context.Context) { if ctx.Repo.Repository.IsBare { - ctx.Handle(404, "MustBeNotBare", nil) + ctx.NotFound("MustBeNotBare", nil) } } // MustBeEditable check that repo can be edited func MustBeEditable(ctx *context.Context) { if !ctx.Repo.Repository.CanEnableEditor() || ctx.Repo.IsViewCommit { - ctx.Handle(404, "", nil) + ctx.NotFound("", nil) return } } @@ -46,14 +46,14 @@ func MustBeEditable(ctx *context.Context) { // MustBeAbleToUpload check that repo can be uploaded to func MustBeAbleToUpload(ctx *context.Context) { if !setting.Repository.Upload.Enabled { - ctx.Handle(404, "", nil) + ctx.NotFound("", nil) } } func checkContextUser(ctx *context.Context, uid int64) *models.User { orgs, err := models.GetOwnedOrgsByUserIDDesc(ctx.User.ID, "updated_unix") if err != nil { - ctx.Handle(500, "GetOwnedOrgsByUserIDDesc", err) + ctx.ServerError("GetOwnedOrgsByUserIDDesc", err) return nil } ctx.Data["Orgs"] = orgs @@ -69,7 +69,7 @@ func checkContextUser(ctx *context.Context, uid int64) *models.User { } if err != nil { - ctx.Handle(500, "GetUserByID", fmt.Errorf("[%d]: %v", uid, err)) + ctx.ServerError("GetUserByID", fmt.Errorf("[%d]: %v", uid, err)) return nil } @@ -81,7 +81,7 @@ func checkContextUser(ctx *context.Context, uid int64) *models.User { if !ctx.User.IsAdmin { isOwner, err := org.IsOwnedBy(ctx.User.ID) if err != nil { - ctx.Handle(500, "IsOwnedBy", err) + ctx.ServerError("IsOwnedBy", err) return nil } else if !isOwner { ctx.Error(403) @@ -143,7 +143,7 @@ func handleCreateError(ctx *context.Context, owner *models.User, err error, name ctx.Data["Err_RepoName"] = true ctx.RenderWithErr(ctx.Tr("repo.form.name_pattern_not_allowed", err.(models.ErrNamePatternNotAllowed).Pattern), tpl, form) default: - ctx.Handle(500, name, err) + ctx.ServerError(name, err) } } @@ -235,10 +235,10 @@ func MigratePost(ctx *context.Context, form auth.MigrateRepoForm) { case addrErr.IsInvalidPath: ctx.RenderWithErr(ctx.Tr("repo.migrate.invalid_local_path"), tplMigrate, &form) default: - ctx.Handle(500, "Unknown error", err) + ctx.ServerError("Unknown error", err) } } else { - ctx.Handle(500, "ParseRemoteAddr", err) + ctx.ServerError("ParseRemoteAddr", err) } return } @@ -303,7 +303,7 @@ func Action(ctx *context.Context) { } if err != nil { - ctx.Handle(500, fmt.Sprintf("Action (%s)", ctx.Params(":action")), err) + ctx.ServerError(fmt.Sprintf("Action (%s)", ctx.Params(":action")), err) return } @@ -342,7 +342,7 @@ func Download(ctx *context.Context) { if !com.IsDir(archivePath) { if err := os.MkdirAll(archivePath, os.ModePerm); err != nil { - ctx.Handle(500, "Download -> os.MkdirAll(archivePath)", err) + ctx.ServerError("Download -> os.MkdirAll(archivePath)", err) return } } @@ -356,30 +356,30 @@ func Download(ctx *context.Context) { if gitRepo.IsBranchExist(refName) { commit, err = gitRepo.GetBranchCommit(refName) if err != nil { - ctx.Handle(500, "GetBranchCommit", err) + ctx.ServerError("GetBranchCommit", err) return } } else if gitRepo.IsTagExist(refName) { commit, err = gitRepo.GetTagCommit(refName) if err != nil { - ctx.Handle(500, "GetTagCommit", err) + ctx.ServerError("GetTagCommit", err) return } } else if len(refName) >= 4 && len(refName) <= 40 { commit, err = gitRepo.GetCommit(refName) if err != nil { - ctx.Handle(404, "GetCommit", nil) + ctx.NotFound("GetCommit", nil) return } } else { - ctx.Handle(404, "Download", nil) + ctx.NotFound("Download", nil) return } archivePath = path.Join(archivePath, base.ShortSha(commit.ID.String())+ext) if !com.IsFile(archivePath) { if err := commit.CreateArchive(archivePath, archiveType); err != nil { - ctx.Handle(500, "Download -> CreateArchive "+archivePath, err) + ctx.ServerError("Download -> CreateArchive "+archivePath, err) return } } diff --git a/routers/repo/search.go b/routers/repo/search.go index bf260ac8e4..ed209f2ddc 100644 --- a/routers/repo/search.go +++ b/routers/repo/search.go @@ -31,7 +31,7 @@ func Search(ctx *context.Context) { } total, searchResults, err := search.PerformSearch(ctx.Repo.Repository.ID, keyword, page, setting.UI.RepoSearchPagingNum) if err != nil { - ctx.Handle(500, "SearchResults", err) + ctx.ServerError("SearchResults", err) return } ctx.Data["Keyword"] = keyword diff --git a/routers/repo/setting.go b/routers/repo/setting.go index d7a61ba268..6986658b75 100644 --- a/routers/repo/setting.go +++ b/routers/repo/setting.go @@ -67,14 +67,14 @@ func SettingsPost(ctx *context.Context, form auth.RepoSettingForm) { case models.IsErrNamePatternNotAllowed(err): ctx.RenderWithErr(ctx.Tr("repo.form.name_pattern_not_allowed", err.(models.ErrNamePatternNotAllowed).Pattern), tplSettingsOptions, &form) default: - ctx.Handle(500, "ChangeRepositoryName", err) + ctx.ServerError("ChangeRepositoryName", err) } return } err := models.NewRepoRedirect(ctx.Repo.Owner.ID, repo.ID, repo.Name, newRepoName) if err != nil { - ctx.Handle(500, "NewRepoRedirect", err) + ctx.ServerError("NewRepoRedirect", err) return } @@ -94,7 +94,7 @@ func SettingsPost(ctx *context.Context, form auth.RepoSettingForm) { visibilityChanged := repo.IsPrivate != form.Private repo.IsPrivate = form.Private if err := models.UpdateRepository(repo, visibilityChanged); err != nil { - ctx.Handle(500, "UpdateRepository", err) + ctx.ServerError("UpdateRepository", err) return } log.Trace("Repository basic settings updated: %s/%s", ctx.Repo.Owner.Name, repo.Name) @@ -110,7 +110,7 @@ func SettingsPost(ctx *context.Context, form auth.RepoSettingForm) { case "mirror": if !repo.IsMirror { - ctx.Handle(404, "", nil) + ctx.NotFound("", nil) return } @@ -127,7 +127,7 @@ func SettingsPost(ctx *context.Context, form auth.RepoSettingForm) { } } if err := ctx.Repo.Mirror.SaveAddress(form.MirrorAddress); err != nil { - ctx.Handle(500, "SaveAddress", err) + ctx.ServerError("SaveAddress", err) return } @@ -136,7 +136,7 @@ func SettingsPost(ctx *context.Context, form auth.RepoSettingForm) { case "mirror-sync": if !repo.IsMirror { - ctx.Handle(404, "", nil) + ctx.NotFound("", nil) return } @@ -221,7 +221,7 @@ func SettingsPost(ctx *context.Context, form auth.RepoSettingForm) { } if err := models.UpdateRepositoryUnits(repo, units); err != nil { - ctx.Handle(500, "UpdateRepositoryUnits", err) + ctx.ServerError("UpdateRepositoryUnits", err) return } log.Trace("Repository advanced settings updated: %s/%s", ctx.Repo.Owner.Name, repo.Name) @@ -246,10 +246,10 @@ func SettingsPost(ctx *context.Context, form auth.RepoSettingForm) { repo.IsMirror = false if _, err := models.CleanUpMigrateInfo(repo); err != nil { - ctx.Handle(500, "CleanUpMigrateInfo", err) + ctx.ServerError("CleanUpMigrateInfo", err) return } else if err = models.DeleteMirrorByRepoID(ctx.Repo.Repository.ID); err != nil { - ctx.Handle(500, "DeleteMirrorByRepoID", err) + ctx.ServerError("DeleteMirrorByRepoID", err) return } log.Trace("Repository converted from mirror to regular: %s/%s", ctx.Repo.Owner.Name, repo.Name) @@ -269,7 +269,7 @@ func SettingsPost(ctx *context.Context, form auth.RepoSettingForm) { newOwner := ctx.Query("new_owner_name") isExist, err := models.IsUserExist(0, newOwner) if err != nil { - ctx.Handle(500, "IsUserExist", err) + ctx.ServerError("IsUserExist", err) return } else if !isExist { ctx.RenderWithErr(ctx.Tr("form.enterred_invalid_owner_name"), tplSettingsOptions, nil) @@ -280,7 +280,7 @@ func SettingsPost(ctx *context.Context, form auth.RepoSettingForm) { if models.IsErrRepoAlreadyExist(err) { ctx.RenderWithErr(ctx.Tr("repo.settings.new_owner_has_same_repo"), tplSettingsOptions, nil) } else { - ctx.Handle(500, "TransferOwnership", err) + ctx.ServerError("TransferOwnership", err) } return } @@ -299,7 +299,7 @@ func SettingsPost(ctx *context.Context, form auth.RepoSettingForm) { } if err := models.DeleteRepository(ctx.User, ctx.Repo.Owner.ID, repo.ID); err != nil { - ctx.Handle(500, "DeleteRepository", err) + ctx.ServerError("DeleteRepository", err) return } log.Trace("Repository deleted: %s/%s", ctx.Repo.Owner.Name, repo.Name) @@ -324,7 +324,7 @@ func SettingsPost(ctx *context.Context, form auth.RepoSettingForm) { ctx.Redirect(ctx.Repo.RepoLink + "/settings") default: - ctx.Handle(404, "", nil) + ctx.NotFound("", nil) } } @@ -335,7 +335,7 @@ func Collaboration(ctx *context.Context) { users, err := ctx.Repo.Repository.GetCollaborators() if err != nil { - ctx.Handle(500, "GetCollaborators", err) + ctx.ServerError("GetCollaborators", err) return } ctx.Data["Collaborators"] = users @@ -357,7 +357,7 @@ func CollaborationPost(ctx *context.Context) { ctx.Flash.Error(ctx.Tr("form.user_not_exist")) ctx.Redirect(setting.AppSubURL + ctx.Req.URL.Path) } else { - ctx.Handle(500, "GetUserByName", err) + ctx.ServerError("GetUserByName", err) } return } @@ -373,7 +373,7 @@ func CollaborationPost(ctx *context.Context) { if ctx.Repo.Owner.IsOrganization() { isMember, err := ctx.Repo.Owner.IsOrgMember(u.ID) if err != nil { - ctx.Handle(500, "IsOrgMember", err) + ctx.ServerError("IsOrgMember", err) return } else if isMember { ctx.Flash.Info(ctx.Tr("repo.settings.user_is_org_member")) @@ -383,7 +383,7 @@ func CollaborationPost(ctx *context.Context) { } if err = ctx.Repo.Repository.AddCollaborator(u); err != nil { - ctx.Handle(500, "AddCollaborator", err) + ctx.ServerError("AddCollaborator", err) return } @@ -422,9 +422,9 @@ func parseOwnerAndRepo(ctx *context.Context) (*models.User, *models.Repository) owner, err := models.GetUserByName(ctx.Params(":username")) if err != nil { if models.IsErrUserNotExist(err) { - ctx.Handle(404, "GetUserByName", err) + ctx.NotFound("GetUserByName", err) } else { - ctx.Handle(500, "GetUserByName", err) + ctx.ServerError("GetUserByName", err) } return nil, nil } @@ -432,9 +432,9 @@ func parseOwnerAndRepo(ctx *context.Context) (*models.User, *models.Repository) repo, err := models.GetRepositoryByName(owner.ID, ctx.Params(":reponame")) if err != nil { if models.IsErrRepoNotExist(err) { - ctx.Handle(404, "GetRepositoryByName", err) + ctx.NotFound("GetRepositoryByName", err) } else { - ctx.Handle(500, "GetRepositoryByName", err) + ctx.ServerError("GetRepositoryByName", err) } return nil, nil } @@ -449,7 +449,7 @@ func GitHooks(ctx *context.Context) { hooks, err := ctx.Repo.GitRepo.Hooks() if err != nil { - ctx.Handle(500, "Hooks", err) + ctx.ServerError("Hooks", err) return } ctx.Data["Hooks"] = hooks @@ -466,9 +466,9 @@ func GitHooksEdit(ctx *context.Context) { hook, err := ctx.Repo.GitRepo.GetHook(name) if err != nil { if err == git.ErrNotValidHook { - ctx.Handle(404, "GetHook", err) + ctx.NotFound("GetHook", err) } else { - ctx.Handle(500, "GetHook", err) + ctx.ServerError("GetHook", err) } return } @@ -482,15 +482,15 @@ func GitHooksEditPost(ctx *context.Context) { hook, err := ctx.Repo.GitRepo.GetHook(name) if err != nil { if err == git.ErrNotValidHook { - ctx.Handle(404, "GetHook", err) + ctx.NotFound("GetHook", err) } else { - ctx.Handle(500, "GetHook", err) + ctx.ServerError("GetHook", err) } return } hook.Content = ctx.Query("content") if err = hook.Update(); err != nil { - ctx.Handle(500, "hook.Update", err) + ctx.ServerError("hook.Update", err) return } ctx.Redirect(ctx.Repo.RepoLink + "/settings/hooks/git") @@ -504,7 +504,7 @@ func DeployKeys(ctx *context.Context) { keys, err := models.ListDeployKeys(ctx.Repo.Repository.ID) if err != nil { - ctx.Handle(500, "ListDeployKeys", err) + ctx.ServerError("ListDeployKeys", err) return } ctx.Data["Deploykeys"] = keys @@ -519,7 +519,7 @@ func DeployKeysPost(ctx *context.Context, form auth.AddKeyForm) { keys, err := models.ListDeployKeys(ctx.Repo.Repository.ID) if err != nil { - ctx.Handle(500, "ListDeployKeys", err) + ctx.ServerError("ListDeployKeys", err) return } ctx.Data["Deploykeys"] = keys @@ -555,7 +555,7 @@ func DeployKeysPost(ctx *context.Context, form auth.AddKeyForm) { ctx.Data["Err_Title"] = true ctx.RenderWithErr(ctx.Tr("repo.settings.key_name_used"), tplDeployKeys, &form) default: - ctx.Handle(500, "AddDeployKey", err) + ctx.ServerError("AddDeployKey", err) } return } diff --git a/routers/repo/setting_protected_branch.go b/routers/repo/setting_protected_branch.go index 7ab8ca218e..b8ff6d6ecd 100644 --- a/routers/repo/setting_protected_branch.go +++ b/routers/repo/setting_protected_branch.go @@ -24,7 +24,7 @@ func ProtectedBranch(ctx *context.Context) { protectedBranches, err := ctx.Repo.Repository.GetProtectedBranches() if err != nil { - ctx.Handle(500, "GetProtectedBranches", err) + ctx.ServerError("GetProtectedBranches", err) return } ctx.Data["ProtectedBranches"] = protectedBranches @@ -71,12 +71,12 @@ func ProtectedBranchPost(ctx *context.Context) { repo.DefaultBranch = branch if err := ctx.Repo.GitRepo.SetDefaultBranch(branch); err != nil { if !git.IsErrUnsupportedVersion(err) { - ctx.Handle(500, "SetDefaultBranch", err) + ctx.ServerError("SetDefaultBranch", err) return } } if err := repo.UpdateDefaultBranch(); err != nil { - ctx.Handle(500, "SetDefaultBranch", err) + ctx.ServerError("SetDefaultBranch", err) return } } @@ -86,7 +86,7 @@ func ProtectedBranchPost(ctx *context.Context) { ctx.Flash.Success(ctx.Tr("repo.settings.update_settings_success")) ctx.Redirect(setting.AppSubURL + ctx.Req.URL.Path) default: - ctx.Handle(404, "", nil) + ctx.NotFound("", nil) } } @@ -94,7 +94,7 @@ func ProtectedBranchPost(ctx *context.Context) { func SettingsProtectedBranch(c *context.Context) { branch := c.Params("*") if !c.Repo.GitRepo.IsBranchExist(branch) { - c.NotFound() + c.NotFound("IsBranchExist", nil) return } @@ -104,7 +104,7 @@ func SettingsProtectedBranch(c *context.Context) { protectBranch, err := models.GetProtectedBranchBy(c.Repo.Repository.ID, branch) if err != nil { if !models.IsErrBranchNotExist(err) { - c.Handle(500, "GetProtectBranchOfRepoByName", err) + c.ServerError("GetProtectBranchOfRepoByName", err) return } } @@ -118,7 +118,7 @@ func SettingsProtectedBranch(c *context.Context) { users, err := c.Repo.Repository.GetWriters() if err != nil { - c.Handle(500, "Repo.Repository.GetWriters", err) + c.ServerError("Repo.Repository.GetWriters", err) return } c.Data["Users"] = users @@ -127,7 +127,7 @@ func SettingsProtectedBranch(c *context.Context) { if c.Repo.Owner.IsOrganization() { teams, err := c.Repo.Owner.TeamsWithAccessToRepo(c.Repo.Repository.ID, models.AccessModeWrite) if err != nil { - c.Handle(500, "Repo.Owner.TeamsWithAccessToRepo", err) + c.ServerError("Repo.Owner.TeamsWithAccessToRepo", err) return } c.Data["Teams"] = teams @@ -142,14 +142,14 @@ func SettingsProtectedBranch(c *context.Context) { func SettingsProtectedBranchPost(ctx *context.Context, f auth.ProtectBranchForm) { branch := ctx.Params("*") if !ctx.Repo.GitRepo.IsBranchExist(branch) { - ctx.NotFound() + ctx.NotFound("IsBranchExist", nil) return } protectBranch, err := models.GetProtectedBranchBy(ctx.Repo.Repository.ID, branch) if err != nil { if !models.IsErrBranchNotExist(err) { - ctx.Handle(500, "GetProtectBranchOfRepoByName", err) + ctx.ServerError("GetProtectBranchOfRepoByName", err) return } } @@ -168,7 +168,7 @@ func SettingsProtectedBranchPost(ctx *context.Context, f auth.ProtectBranchForm) whitelistTeams, _ := base.StringsToInt64s(strings.Split(f.WhitelistTeams, ",")) err = models.UpdateProtectBranch(ctx.Repo.Repository, protectBranch, whitelistUsers, whitelistTeams) if err != nil { - ctx.Handle(500, "UpdateProtectBranch", err) + ctx.ServerError("UpdateProtectBranch", err) return } ctx.Flash.Success(ctx.Tr("repo.settings.update_protect_branch_success", branch)) @@ -176,7 +176,7 @@ func SettingsProtectedBranchPost(ctx *context.Context, f auth.ProtectBranchForm) } else { if protectBranch != nil { if err := ctx.Repo.Repository.DeleteProtectedBranch(protectBranch.ID); err != nil { - ctx.Handle(500, "DeleteProtectedBranch", err) + ctx.ServerError("DeleteProtectedBranch", err) return } } diff --git a/routers/repo/view.go b/routers/repo/view.go index 512af27fc4..685dd411d6 100644 --- a/routers/repo/view.go +++ b/routers/repo/view.go @@ -44,14 +44,14 @@ func renderDirectory(ctx *context.Context, treeLink string) { entries, err := tree.ListEntries() if err != nil { - ctx.Handle(500, "ListEntries", err) + ctx.ServerError("ListEntries", err) return } entries.CustomSort(base.NaturalSortLess) ctx.Data["Files"], err = entries.GetCommitsInfo(ctx.Repo.Commit, ctx.Repo.TreePath) if err != nil { - ctx.Handle(500, "GetCommitsInfo", err) + ctx.ServerError("GetCommitsInfo", err) return } @@ -78,7 +78,7 @@ func renderDirectory(ctx *context.Context, treeLink string) { dataRc, err := readmeFile.DataAsync() if err != nil { - ctx.Handle(500, "Data", err) + ctx.ServerError("Data", err) return } defer dataRc.Close() @@ -117,7 +117,7 @@ func renderDirectory(ctx *context.Context, treeLink string) { if len(ctx.Repo.TreePath) > 0 { latestCommit, err = ctx.Repo.Commit.GetCommitByPath(ctx.Repo.TreePath) if err != nil { - ctx.Handle(500, "GetCommitByPath", err) + ctx.ServerError("GetCommitByPath", err) return } } @@ -145,7 +145,7 @@ func renderFile(ctx *context.Context, entry *git.TreeEntry, treeLink, rawLink st blob := entry.Blob() dataRc, err := blob.DataAsync() if err != nil { - ctx.Handle(500, "DataAsync", err) + ctx.ServerError("DataAsync", err) return } defer dataRc.Close() @@ -288,7 +288,7 @@ func Home(ctx *context.Context) { } } - ctx.Handle(404, "Home", fmt.Errorf(ctx.Tr("units.error.no_unit_allowed_repo"))) + ctx.NotFound("Home", fmt.Errorf(ctx.Tr("units.error.no_unit_allowed_repo"))) } func renderCode(ctx *context.Context) { @@ -362,7 +362,7 @@ func RenderUserCards(ctx *context.Context, total int, getter func(page int) ([]* items, err := getter(pager.Current()) if err != nil { - ctx.Handle(500, "getter", err) + ctx.ServerError("getter", err) return } ctx.Data["Cards"] = items @@ -392,13 +392,13 @@ func Forks(ctx *context.Context) { forks, err := ctx.Repo.Repository.GetForks() if err != nil { - ctx.Handle(500, "GetForks", err) + ctx.ServerError("GetForks", err) return } for _, fork := range forks { if err = fork.GetOwner(); err != nil { - ctx.Handle(500, "GetOwner", err) + ctx.ServerError("GetOwner", err) return } } diff --git a/routers/repo/webhook.go b/routers/repo/webhook.go index 8fdc32849d..35fdf796b5 100644 --- a/routers/repo/webhook.go +++ b/routers/repo/webhook.go @@ -37,7 +37,7 @@ func Webhooks(ctx *context.Context) { ws, err := models.GetWebhooksByRepoID(ctx.Repo.Repository.ID) if err != nil { - ctx.Handle(500, "GetWebhooksByRepoID", err) + ctx.ServerError("GetWebhooksByRepoID", err) return } ctx.Data["Webhooks"] = ws @@ -76,7 +76,7 @@ func getOrgRepoCtx(ctx *context.Context) (*orgRepoCtx, error) { func checkHookType(ctx *context.Context) string { hookType := strings.ToLower(ctx.Params(":type")) if !com.IsSliceContainsStr(setting.Webhook.Types, hookType) { - ctx.Handle(404, "checkHookType", nil) + ctx.NotFound("checkHookType", nil) return "" } return hookType @@ -91,7 +91,7 @@ func WebhooksNew(ctx *context.Context) { orCtx, err := getOrgRepoCtx(ctx) if err != nil { - ctx.Handle(500, "getOrgRepoCtx", err) + ctx.ServerError("getOrgRepoCtx", err) return } @@ -136,7 +136,7 @@ func WebHooksNewPost(ctx *context.Context, form auth.NewWebhookForm) { orCtx, err := getOrgRepoCtx(ctx) if err != nil { - ctx.Handle(500, "getOrgRepoCtx", err) + ctx.ServerError("getOrgRepoCtx", err) return } ctx.Data["BaseLink"] = orCtx.Link @@ -162,10 +162,10 @@ func WebHooksNewPost(ctx *context.Context, form auth.NewWebhookForm) { OrgID: orCtx.OrgID, } if err := w.UpdateEvent(); err != nil { - ctx.Handle(500, "UpdateEvent", err) + ctx.ServerError("UpdateEvent", err) return } else if err := models.CreateWebhook(w); err != nil { - ctx.Handle(500, "CreateWebhook", err) + ctx.ServerError("CreateWebhook", err) return } @@ -183,7 +183,7 @@ func GogsHooksNewPost(ctx *context.Context, form auth.NewGogshookForm) { orCtx, err := getOrgRepoCtx(ctx) if err != nil { - ctx.Handle(500, "getOrgRepoCtx", err) + ctx.ServerError("getOrgRepoCtx", err) return } ctx.Data["BaseLink"] = orCtx.Link @@ -209,10 +209,10 @@ func GogsHooksNewPost(ctx *context.Context, form auth.NewGogshookForm) { OrgID: orCtx.OrgID, } if err := w.UpdateEvent(); err != nil { - ctx.Handle(500, "UpdateEvent", err) + ctx.ServerError("UpdateEvent", err) return } else if err := models.CreateWebhook(w); err != nil { - ctx.Handle(500, "CreateWebhook", err) + ctx.ServerError("CreateWebhook", err) return } @@ -229,7 +229,7 @@ func DiscordHooksNewPost(ctx *context.Context, form auth.NewDiscordHookForm) { orCtx, err := getOrgRepoCtx(ctx) if err != nil { - ctx.Handle(500, "getOrgRepoCtx", err) + ctx.ServerError("getOrgRepoCtx", err) return } @@ -243,7 +243,7 @@ func DiscordHooksNewPost(ctx *context.Context, form auth.NewDiscordHookForm) { IconURL: form.IconURL, }) if err != nil { - ctx.Handle(500, "Marshal", err) + ctx.ServerError("Marshal", err) return } @@ -258,10 +258,10 @@ func DiscordHooksNewPost(ctx *context.Context, form auth.NewDiscordHookForm) { OrgID: orCtx.OrgID, } if err := w.UpdateEvent(); err != nil { - ctx.Handle(500, "UpdateEvent", err) + ctx.ServerError("UpdateEvent", err) return } else if err := models.CreateWebhook(w); err != nil { - ctx.Handle(500, "CreateWebhook", err) + ctx.ServerError("CreateWebhook", err) return } @@ -278,7 +278,7 @@ func DingtalkHooksNewPost(ctx *context.Context, form auth.NewDingtalkHookForm) { orCtx, err := getOrgRepoCtx(ctx) if err != nil { - ctx.Handle(500, "getOrgRepoCtx", err) + ctx.ServerError("getOrgRepoCtx", err) return } @@ -298,10 +298,10 @@ func DingtalkHooksNewPost(ctx *context.Context, form auth.NewDingtalkHookForm) { OrgID: orCtx.OrgID, } if err := w.UpdateEvent(); err != nil { - ctx.Handle(500, "UpdateEvent", err) + ctx.ServerError("UpdateEvent", err) return } else if err := models.CreateWebhook(w); err != nil { - ctx.Handle(500, "CreateWebhook", err) + ctx.ServerError("CreateWebhook", err) return } @@ -318,7 +318,7 @@ func SlackHooksNewPost(ctx *context.Context, form auth.NewSlackHookForm) { orCtx, err := getOrgRepoCtx(ctx) if err != nil { - ctx.Handle(500, "getOrgRepoCtx", err) + ctx.ServerError("getOrgRepoCtx", err) return } @@ -334,7 +334,7 @@ func SlackHooksNewPost(ctx *context.Context, form auth.NewSlackHookForm) { Color: form.Color, }) if err != nil { - ctx.Handle(500, "Marshal", err) + ctx.ServerError("Marshal", err) return } @@ -349,10 +349,10 @@ func SlackHooksNewPost(ctx *context.Context, form auth.NewSlackHookForm) { OrgID: orCtx.OrgID, } if err := w.UpdateEvent(); err != nil { - ctx.Handle(500, "UpdateEvent", err) + ctx.ServerError("UpdateEvent", err) return } else if err := models.CreateWebhook(w); err != nil { - ctx.Handle(500, "CreateWebhook", err) + ctx.ServerError("CreateWebhook", err) return } @@ -365,7 +365,7 @@ func checkWebhook(ctx *context.Context) (*orgRepoCtx, *models.Webhook) { orCtx, err := getOrgRepoCtx(ctx) if err != nil { - ctx.Handle(500, "getOrgRepoCtx", err) + ctx.ServerError("getOrgRepoCtx", err) return nil, nil } ctx.Data["BaseLink"] = orCtx.Link @@ -378,9 +378,9 @@ func checkWebhook(ctx *context.Context) (*orgRepoCtx, *models.Webhook) { } if err != nil { if models.IsErrWebhookNotExist(err) { - ctx.Handle(404, "GetWebhookByID", nil) + ctx.NotFound("GetWebhookByID", nil) } else { - ctx.Handle(500, "GetWebhookByID", err) + ctx.ServerError("GetWebhookByID", err) } return nil, nil } @@ -395,7 +395,7 @@ func checkWebhook(ctx *context.Context) (*orgRepoCtx, *models.Webhook) { ctx.Data["History"], err = w.History(1) if err != nil { - ctx.Handle(500, "History", err) + ctx.ServerError("History", err) } return orCtx, w } @@ -443,10 +443,10 @@ func WebHooksEditPost(ctx *context.Context, form auth.NewWebhookForm) { w.HookEvent = ParseHookEvent(form.WebhookForm) w.IsActive = form.Active if err := w.UpdateEvent(); err != nil { - ctx.Handle(500, "UpdateEvent", err) + ctx.ServerError("UpdateEvent", err) return } else if err := models.UpdateWebhook(w); err != nil { - ctx.Handle(500, "WebHooksEditPost", err) + ctx.ServerError("WebHooksEditPost", err) return } @@ -482,10 +482,10 @@ func GogsHooksEditPost(ctx *context.Context, form auth.NewGogshookForm) { w.HookEvent = ParseHookEvent(form.WebhookForm) w.IsActive = form.Active if err := w.UpdateEvent(); err != nil { - ctx.Handle(500, "UpdateEvent", err) + ctx.ServerError("UpdateEvent", err) return } else if err := models.UpdateWebhook(w); err != nil { - ctx.Handle(500, "GogsHooksEditPost", err) + ctx.ServerError("GogsHooksEditPost", err) return } @@ -517,7 +517,7 @@ func SlackHooksEditPost(ctx *context.Context, form auth.NewSlackHookForm) { Color: form.Color, }) if err != nil { - ctx.Handle(500, "Marshal", err) + ctx.ServerError("Marshal", err) return } @@ -526,10 +526,10 @@ func SlackHooksEditPost(ctx *context.Context, form auth.NewSlackHookForm) { w.HookEvent = ParseHookEvent(form.WebhookForm) w.IsActive = form.Active if err := w.UpdateEvent(); err != nil { - ctx.Handle(500, "UpdateEvent", err) + ctx.ServerError("UpdateEvent", err) return } else if err := models.UpdateWebhook(w); err != nil { - ctx.Handle(500, "UpdateWebhook", err) + ctx.ServerError("UpdateWebhook", err) return } @@ -559,7 +559,7 @@ func DiscordHooksEditPost(ctx *context.Context, form auth.NewDiscordHookForm) { IconURL: form.IconURL, }) if err != nil { - ctx.Handle(500, "Marshal", err) + ctx.ServerError("Marshal", err) return } @@ -568,10 +568,10 @@ func DiscordHooksEditPost(ctx *context.Context, form auth.NewDiscordHookForm) { w.HookEvent = ParseHookEvent(form.WebhookForm) w.IsActive = form.Active if err := w.UpdateEvent(); err != nil { - ctx.Handle(500, "UpdateEvent", err) + ctx.ServerError("UpdateEvent", err) return } else if err := models.UpdateWebhook(w); err != nil { - ctx.Handle(500, "UpdateWebhook", err) + ctx.ServerError("UpdateWebhook", err) return } @@ -600,10 +600,10 @@ func DingtalkHooksEditPost(ctx *context.Context, form auth.NewDingtalkHookForm) w.HookEvent = ParseHookEvent(form.WebhookForm) w.IsActive = form.Active if err := w.UpdateEvent(); err != nil { - ctx.Handle(500, "UpdateEvent", err) + ctx.ServerError("UpdateEvent", err) return } else if err := models.UpdateWebhook(w); err != nil { - ctx.Handle(500, "UpdateWebhook", err) + ctx.ServerError("UpdateWebhook", err) return } diff --git a/routers/repo/wiki.go b/routers/repo/wiki.go index 8aa9ed8df7..7befe7c687 100644 --- a/routers/repo/wiki.go +++ b/routers/repo/wiki.go @@ -32,7 +32,7 @@ const ( func MustEnableWiki(ctx *context.Context) { if !ctx.Repo.Repository.UnitEnabled(models.UnitTypeWiki) && !ctx.Repo.Repository.UnitEnabled(models.UnitTypeExternalWiki) { - ctx.Handle(404, "MustEnableWiki", nil) + ctx.NotFound("MustEnableWiki", nil) return } @@ -67,13 +67,13 @@ func findEntryForFile(commit *git.Commit, target string) (*git.TreeEntry, error) func findWikiRepoCommit(ctx *context.Context) (*git.Repository, *git.Commit, error) { wikiRepo, err := git.OpenRepository(ctx.Repo.Repository.WikiPath()) if err != nil { - ctx.Handle(500, "OpenRepository", err) + ctx.ServerError("OpenRepository", err) return nil, nil, err } commit, err := wikiRepo.GetBranchCommit("master") if err != nil { - ctx.Handle(500, "GetBranchCommit", err) + ctx.ServerError("GetBranchCommit", err) return wikiRepo, nil, err } return wikiRepo, commit, nil @@ -84,12 +84,12 @@ func findWikiRepoCommit(ctx *context.Context) (*git.Repository, *git.Commit, err func wikiContentsByEntry(ctx *context.Context, entry *git.TreeEntry) []byte { reader, err := entry.Blob().Data() if err != nil { - ctx.Handle(500, "Blob.Data", err) + ctx.ServerError("Blob.Data", err) return nil } content, err := ioutil.ReadAll(reader) if err != nil { - ctx.Handle(500, "ReadAll", err) + ctx.ServerError("ReadAll", err) return nil } return content @@ -100,7 +100,7 @@ func wikiContentsByEntry(ctx *context.Context, entry *git.TreeEntry) []byte { func wikiContentsByName(ctx *context.Context, commit *git.Commit, wikiName string) ([]byte, bool) { entry, err := findEntryForFile(commit, models.WikiNameToFilename(wikiName)) if err != nil { - ctx.Handle(500, "findEntryForFile", err) + ctx.ServerError("findEntryForFile", err) return nil, false } else if entry == nil { return nil, false @@ -118,7 +118,7 @@ func renderWikiPage(ctx *context.Context, isViewPage bool) (*git.Repository, *gi if isViewPage { entries, err := commit.ListEntries() if err != nil { - ctx.Handle(500, "ListEntries", err) + ctx.ServerError("ListEntries", err) return nil, nil } pages := make([]PageMeta, 0, len(entries)) @@ -128,7 +128,7 @@ func renderWikiPage(ctx *context.Context, isViewPage bool) (*git.Repository, *gi } wikiName, err := models.WikiFilenameToName(entry.Name()) if err != nil { - ctx.Handle(500, "WikiFilenameToName", err) + ctx.ServerError("WikiFilenameToName", err) return nil, nil } else if wikiName == "_Sidebar" || wikiName == "_Footer" { continue @@ -155,7 +155,7 @@ func renderWikiPage(ctx *context.Context, isViewPage bool) (*git.Repository, *gi pageFilename := models.WikiNameToFilename(pageName) var entry *git.TreeEntry if entry, err = findEntryForFile(commit, pageFilename); err != nil { - ctx.Handle(500, "findEntryForFile", err) + ctx.ServerError("findEntryForFile", err) return nil, nil } else if entry == nil { ctx.Redirect(ctx.Repo.RepoLink + "/wiki/_pages") @@ -222,7 +222,7 @@ func Wiki(ctx *context.Context) { // Get last change information. lastCommit, err := wikiRepo.GetCommitByPath(wikiPath) if err != nil { - ctx.Handle(500, "GetCommitByPath", err) + ctx.ServerError("GetCommitByPath", err) return } ctx.Data["Author"] = lastCommit.Author @@ -247,7 +247,7 @@ func WikiPages(ctx *context.Context) { entries, err := commit.ListEntries() if err != nil { - ctx.Handle(500, "ListEntries", err) + ctx.ServerError("ListEntries", err) return } pages := make([]PageMeta, 0, len(entries)) @@ -257,12 +257,12 @@ func WikiPages(ctx *context.Context) { } c, err := wikiRepo.GetCommitByPath(entry.Name()) if err != nil { - ctx.Handle(500, "GetCommit", err) + ctx.ServerError("GetCommit", err) return } wikiName, err := models.WikiFilenameToName(entry.Name()) if err != nil { - ctx.Handle(500, "WikiFilenameToName", err) + ctx.ServerError("WikiFilenameToName", err) return } pages = append(pages, PageMeta{ @@ -294,15 +294,15 @@ func WikiRaw(ctx *context.Context) { entry, err = findEntryForFile(commit, wikiPath) } if err != nil { - ctx.Handle(500, "findFile", err) + ctx.ServerError("findFile", err) return } else if entry == nil { - ctx.Handle(404, "findEntryForFile", nil) + ctx.NotFound("findEntryForFile", nil) return } if err = ServeBlob(ctx, entry.Blob()); err != nil { - ctx.Handle(500, "ServeBlob", err) + ctx.ServerError("ServeBlob", err) } } @@ -339,7 +339,7 @@ func NewWikiPost(ctx *context.Context, form auth.NewWikiForm) { ctx.Data["Err_Title"] = true ctx.RenderWithErr(ctx.Tr("repo.wiki.page_already_exists"), tplWikiNew, &form) } else { - ctx.Handle(500, "AddWikiPage", err) + ctx.ServerError("AddWikiPage", err) } return } @@ -381,7 +381,7 @@ func EditWikiPost(ctx *context.Context, form auth.NewWikiForm) { newWikiName := models.NormalizeWikiName(form.Title) if err := ctx.Repo.Repository.EditWikiPage(ctx.User, oldWikiName, newWikiName, form.Content, form.Message); err != nil { - ctx.Handle(500, "EditWikiPage", err) + ctx.ServerError("EditWikiPage", err) return } @@ -396,7 +396,7 @@ func DeleteWikiPagePost(ctx *context.Context) { } if err := ctx.Repo.Repository.DeleteWikiPage(ctx.User, wikiName); err != nil { - ctx.Handle(500, "DeleteWikiPage", err) + ctx.ServerError("DeleteWikiPage", err) return } diff --git a/routers/routes/routes.go b/routers/routes/routes.go index fc7401fc9a..e51bfb946a 100644 --- a/routers/routes/routes.go +++ b/routers/routes/routes.go @@ -312,25 +312,25 @@ func RegisterRoutes(m *macaron.Macaron) { if models.IsErrAttachmentNotExist(err) { ctx.Error(404) } else { - ctx.Handle(500, "GetAttachmentByUUID", err) + ctx.ServerError("GetAttachmentByUUID", err) } return } fr, err := os.Open(attach.LocalPath()) if err != nil { - ctx.Handle(500, "Open", err) + ctx.ServerError("Open", err) return } defer fr.Close() if err := attach.IncreaseDownloadCount(); err != nil { - ctx.Handle(500, "Update", err) + ctx.ServerError("Update", err) return } if err = repo.ServeData(ctx, attach.Name, fr); err != nil { - ctx.Handle(500, "ServeData", err) + ctx.ServerError("ServeData", err) return } }) @@ -353,10 +353,6 @@ func RegisterRoutes(m *macaron.Macaron) { m.Group("", func() { m.Get("/create", org.Create) m.Post("/create", bindIgnErr(auth.CreateOrgForm{}), org.CreatePost) - }, func(ctx *context.Context) { - if !ctx.User.CanCreateOrganization() { - ctx.NotFound() - } }) m.Group("/:org", func() { @@ -575,12 +571,12 @@ func RegisterRoutes(m *macaron.Macaron) { var err error ctx.Repo.Commit, err = ctx.Repo.GitRepo.GetBranchCommit(ctx.Repo.Repository.DefaultBranch) if err != nil { - ctx.Handle(500, "GetBranchCommit", err) + ctx.ServerError("GetBranchCommit", err) return } ctx.Repo.CommitsCount, err = ctx.Repo.GetCommitsCount() if err != nil { - ctx.Handle(500, "GetCommitsCount", err) + ctx.ServerError("GetCommitsCount", err) return } ctx.Data["CommitsCount"] = ctx.Repo.CommitsCount @@ -696,7 +692,7 @@ func RegisterRoutes(m *macaron.Macaron) { m.Post("/:lid/unlock", lfs.UnLockHandler) }, context.RepoAssignment()) m.Any("/*", func(ctx *context.Context) { - ctx.Handle(404, "", nil) + ctx.NotFound("", nil) }) }, ignSignInAndCsrf) m.Any("/*", ignSignInAndCsrf, repo.HTTP) @@ -725,7 +721,7 @@ func RegisterRoutes(m *macaron.Macaron) { if setting.HasRobotsTxt { ctx.ServeFileContent(path.Join(setting.CustomPath, "robots.txt")) } else { - ctx.Handle(404, "", nil) + ctx.NotFound("", nil) } }) diff --git a/routers/user/auth.go b/routers/user/auth.go index f7fb1512a1..c3fb911b07 100644 --- a/routers/user/auth.go +++ b/routers/user/auth.go @@ -81,7 +81,7 @@ func checkAutoLogin(ctx *context.Context) bool { // Check auto-login. isSucceed, err := AutoSignIn(ctx) if err != nil { - ctx.Handle(500, "AutoSignIn", err) + ctx.ServerError("AutoSignIn", err) return true } @@ -116,7 +116,7 @@ func SignIn(ctx *context.Context) { orderedOAuth2Names, oauth2Providers, err := models.GetActiveOAuth2Providers() if err != nil { - ctx.Handle(500, "UserSignIn", err) + ctx.ServerError("UserSignIn", err) return } ctx.Data["OrderedOAuth2Names"] = orderedOAuth2Names @@ -135,7 +135,7 @@ func SignInPost(ctx *context.Context, form auth.SignInForm) { orderedOAuth2Names, oauth2Providers, err := models.GetActiveOAuth2Providers() if err != nil { - ctx.Handle(500, "UserSignIn", err) + ctx.ServerError("UserSignIn", err) return } ctx.Data["OrderedOAuth2Names"] = orderedOAuth2Names @@ -159,7 +159,7 @@ func SignInPost(ctx *context.Context, form auth.SignInForm) { ctx.RenderWithErr(ctx.Tr("form.email_been_used"), tplSignIn, &form) log.Info("Failed authentication attempt for %s from %s", form.UserName, ctx.RemoteAddr()) } else { - ctx.Handle(500, "UserSignIn", err) + ctx.ServerError("UserSignIn", err) } return } @@ -171,7 +171,7 @@ func SignInPost(ctx *context.Context, form auth.SignInForm) { if models.IsErrTwoFactorNotEnrolled(err) { handleSignIn(ctx, u, form.Remember) } else { - ctx.Handle(500, "UserSignIn", err) + ctx.ServerError("UserSignIn", err) } return } @@ -193,7 +193,7 @@ func TwoFactor(ctx *context.Context) { // Ensure user is in a 2FA session. if ctx.Session.Get("twofaUid") == nil { - ctx.Handle(500, "UserSignIn", errors.New("not in 2FA session")) + ctx.ServerError("UserSignIn", errors.New("not in 2FA session")) return } @@ -207,21 +207,21 @@ func TwoFactorPost(ctx *context.Context, form auth.TwoFactorAuthForm) { // Ensure user is in a 2FA session. idSess := ctx.Session.Get("twofaUid") if idSess == nil { - ctx.Handle(500, "UserSignIn", errors.New("not in 2FA session")) + ctx.ServerError("UserSignIn", errors.New("not in 2FA session")) return } id := idSess.(int64) twofa, err := models.GetTwoFactorByUID(id) if err != nil { - ctx.Handle(500, "UserSignIn", err) + ctx.ServerError("UserSignIn", err) return } // Validate the passcode with the stored TOTP secret. ok, err := twofa.ValidateTOTP(form.Passcode) if err != nil { - ctx.Handle(500, "UserSignIn", err) + ctx.ServerError("UserSignIn", err) return } @@ -229,20 +229,20 @@ func TwoFactorPost(ctx *context.Context, form auth.TwoFactorAuthForm) { remember := ctx.Session.Get("twofaRemember").(bool) u, err := models.GetUserByID(id) if err != nil { - ctx.Handle(500, "UserSignIn", err) + ctx.ServerError("UserSignIn", err) return } if ctx.Session.Get("linkAccount") != nil { gothUser := ctx.Session.Get("linkAccountGothUser") if gothUser == nil { - ctx.Handle(500, "UserSignIn", errors.New("not in LinkAccount session")) + ctx.ServerError("UserSignIn", errors.New("not in LinkAccount session")) return } err = models.LinkAccountToUser(u, gothUser.(goth.User)) if err != nil { - ctx.Handle(500, "UserSignIn", err) + ctx.ServerError("UserSignIn", err) return } } @@ -265,7 +265,7 @@ func TwoFactorScratch(ctx *context.Context) { // Ensure user is in a 2FA session. if ctx.Session.Get("twofaUid") == nil { - ctx.Handle(500, "UserSignIn", errors.New("not in 2FA session")) + ctx.ServerError("UserSignIn", errors.New("not in 2FA session")) return } @@ -279,14 +279,14 @@ func TwoFactorScratchPost(ctx *context.Context, form auth.TwoFactorScratchAuthFo // Ensure user is in a 2FA session. idSess := ctx.Session.Get("twofaUid") if idSess == nil { - ctx.Handle(500, "UserSignIn", errors.New("not in 2FA session")) + ctx.ServerError("UserSignIn", errors.New("not in 2FA session")) return } id := idSess.(int64) twofa, err := models.GetTwoFactorByUID(id) if err != nil { - ctx.Handle(500, "UserSignIn", err) + ctx.ServerError("UserSignIn", err) return } @@ -295,14 +295,14 @@ func TwoFactorScratchPost(ctx *context.Context, form auth.TwoFactorScratchAuthFo // Invalidate the scratch token. twofa.ScratchToken = "" if err = models.UpdateTwoFactor(twofa); err != nil { - ctx.Handle(500, "UserSignIn", err) + ctx.ServerError("UserSignIn", err) return } remember := ctx.Session.Get("twofaRemember").(bool) u, err := models.GetUserByID(id) if err != nil { - ctx.Handle(500, "UserSignIn", err) + ctx.ServerError("UserSignIn", err) return } @@ -343,7 +343,7 @@ func handleSignInFull(ctx *context.Context, u *models.User, remember bool, obeyR // Register last login u.SetLastLogin() if err := models.UpdateUserCols(u, "last_login_unix"); err != nil { - ctx.Handle(500, "UpdateUserCols", err) + ctx.ServerError("UpdateUserCols", err) return } @@ -366,7 +366,7 @@ func SignInOAuth(ctx *context.Context) { loginSource, err := models.GetActiveOAuth2LoginSourceByName(provider) if err != nil { - ctx.Handle(500, "SignIn", err) + ctx.ServerError("SignIn", err) return } @@ -380,7 +380,7 @@ func SignInOAuth(ctx *context.Context) { err = oauth2.Auth(loginSource.Name, ctx.Req.Request, ctx.Resp) if err != nil { - ctx.Handle(500, "SignIn", err) + ctx.ServerError("SignIn", err) } // redirect is done in oauth2.Auth } @@ -392,12 +392,12 @@ func SignInOAuthCallback(ctx *context.Context) { // first look if the provider is still active loginSource, err := models.GetActiveOAuth2LoginSourceByName(provider) if err != nil { - ctx.Handle(500, "SignIn", err) + ctx.ServerError("SignIn", err) return } if loginSource == nil { - ctx.Handle(500, "SignIn", errors.New("No valid provider found, check configured callback url in provider")) + ctx.ServerError("SignIn", errors.New("No valid provider found, check configured callback url in provider")) return } @@ -408,7 +408,7 @@ func SignInOAuthCallback(ctx *context.Context) { func handleOAuth2SignIn(u *models.User, gothUser goth.User, ctx *context.Context, err error) { if err != nil { - ctx.Handle(500, "UserSignIn", err) + ctx.ServerError("UserSignIn", err) return } @@ -433,7 +433,7 @@ func handleOAuth2SignIn(u *models.User, gothUser goth.User, ctx *context.Context // Register last login u.SetLastLogin() if err := models.UpdateUserCols(u, "last_login_unix"); err != nil { - ctx.Handle(500, "UpdateUserCols", err) + ctx.ServerError("UpdateUserCols", err) return } @@ -445,7 +445,7 @@ func handleOAuth2SignIn(u *models.User, gothUser goth.User, ctx *context.Context ctx.Redirect(setting.AppSubURL + "/") } else { - ctx.Handle(500, "UserSignIn", err) + ctx.ServerError("UserSignIn", err) } return } @@ -513,7 +513,7 @@ func LinkAccount(ctx *context.Context) { gothUser := ctx.Session.Get("linkAccountGothUser") if gothUser == nil { - ctx.Handle(500, "UserSignIn", errors.New("not in LinkAccount session")) + ctx.ServerError("UserSignIn", errors.New("not in LinkAccount session")) return } @@ -538,7 +538,7 @@ func LinkAccountPostSignIn(ctx *context.Context, signInForm auth.SignInForm) { gothUser := ctx.Session.Get("linkAccountGothUser") if gothUser == nil { - ctx.Handle(500, "UserSignIn", errors.New("not in LinkAccount session")) + ctx.ServerError("UserSignIn", errors.New("not in LinkAccount session")) return } @@ -552,7 +552,7 @@ func LinkAccountPostSignIn(ctx *context.Context, signInForm auth.SignInForm) { if models.IsErrUserNotExist(err) { ctx.RenderWithErr(ctx.Tr("form.username_password_incorrect"), tplLinkAccount, &signInForm) } else { - ctx.Handle(500, "UserLinkAccount", err) + ctx.ServerError("UserLinkAccount", err) } return } @@ -564,12 +564,12 @@ func LinkAccountPostSignIn(ctx *context.Context, signInForm auth.SignInForm) { if models.IsErrTwoFactorNotEnrolled(err) { err = models.LinkAccountToUser(u, gothUser.(goth.User)) if err != nil { - ctx.Handle(500, "UserLinkAccount", err) + ctx.ServerError("UserLinkAccount", err) } else { handleSignIn(ctx, u, signInForm.Remember) } } else { - ctx.Handle(500, "UserLinkAccount", err) + ctx.ServerError("UserLinkAccount", err) } return } @@ -597,7 +597,7 @@ func LinkAccountPostRegister(ctx *context.Context, cpt *captcha.Captcha, form au gothUser := ctx.Session.Get("linkAccountGothUser") if gothUser == nil { - ctx.Handle(500, "UserSignUp", errors.New("not in LinkAccount session")) + ctx.ServerError("UserSignUp", errors.New("not in LinkAccount session")) return } @@ -630,7 +630,7 @@ func LinkAccountPostRegister(ctx *context.Context, cpt *captcha.Captcha, form au loginSource, err := models.GetActiveOAuth2LoginSourceByName(gothUser.(goth.User).Provider) if err != nil { - ctx.Handle(500, "CreateUser", err) + ctx.ServerError("CreateUser", err) } u := &models.User{ @@ -658,7 +658,7 @@ func LinkAccountPostRegister(ctx *context.Context, cpt *captcha.Captcha, form au ctx.Data["Err_UserName"] = true ctx.RenderWithErr(ctx.Tr("user.form.name_pattern_not_allowed", err.(models.ErrNamePatternNotAllowed).Pattern), tplLinkAccount, &form) default: - ctx.Handle(500, "CreateUser", err) + ctx.ServerError("CreateUser", err) } return } @@ -670,7 +670,7 @@ func LinkAccountPostRegister(ctx *context.Context, cpt *captcha.Captcha, form au u.IsActive = true u.SetLastLogin() if err := models.UpdateUserCols(u, "is_admin", "is_active", "last_login_unix"); err != nil { - ctx.Handle(500, "UpdateUser", err) + ctx.ServerError("UpdateUser", err) return } } @@ -774,7 +774,7 @@ func SignUpPost(ctx *context.Context, cpt *captcha.Captcha, form auth.RegisterFo ctx.Data["Err_UserName"] = true ctx.RenderWithErr(ctx.Tr("user.form.name_pattern_not_allowed", err.(models.ErrNamePatternNotAllowed).Pattern), tplSignUp, &form) default: - ctx.Handle(500, "CreateUser", err) + ctx.ServerError("CreateUser", err) } return } @@ -786,7 +786,7 @@ func SignUpPost(ctx *context.Context, cpt *captcha.Captcha, form auth.RegisterFo u.IsActive = true u.SetLastLogin() if err := models.UpdateUserCols(u, "is_admin", "is_active", "last_login_unix"); err != nil { - ctx.Handle(500, "UpdateUser", err) + ctx.ServerError("UpdateUser", err) return } } @@ -841,14 +841,14 @@ func Activate(ctx *context.Context) { user.IsActive = true var err error if user.Rands, err = models.GetUserSalt(); err != nil { - ctx.Handle(500, "UpdateUser", err) + ctx.ServerError("UpdateUser", err) return } if err := models.UpdateUserCols(user, "is_active", "rands"); err != nil { if models.IsErrUserNotExist(err) { ctx.Error(404) } else { - ctx.Handle(500, "UpdateUser", err) + ctx.ServerError("UpdateUser", err) } return } @@ -873,7 +873,7 @@ func ActivateEmail(ctx *context.Context) { // Verify code. if email := models.VerifyActiveEmailCode(code, emailStr); email != nil { if err := email.Activate(); err != nil { - ctx.Handle(500, "ActivateEmail", err) + ctx.ServerError("ActivateEmail", err) } log.Trace("Email activated: %s", email.Email) @@ -906,7 +906,7 @@ func ForgotPasswdPost(ctx *context.Context) { ctx.Data["Title"] = ctx.Tr("auth.forgot_password_title") if setting.MailService == nil { - ctx.Handle(403, "ForgotPasswdPost", nil) + ctx.NotFound("ForgotPasswdPost", nil) return } ctx.Data["IsResetRequest"] = true @@ -923,7 +923,7 @@ func ForgotPasswdPost(ctx *context.Context) { return } - ctx.Handle(500, "user.ResetPasswd(check existence)", err) + ctx.ServerError("user.ResetPasswd(check existence)", err) return } @@ -987,16 +987,16 @@ func ResetPasswdPost(ctx *context.Context) { u.Passwd = passwd var err error if u.Rands, err = models.GetUserSalt(); err != nil { - ctx.Handle(500, "UpdateUser", err) + ctx.ServerError("UpdateUser", err) return } if u.Salt, err = models.GetUserSalt(); err != nil { - ctx.Handle(500, "UpdateUser", err) + ctx.ServerError("UpdateUser", err) return } u.HashPassword() if err := models.UpdateUserCols(u, "passwd", "rands", "salt"); err != nil { - ctx.Handle(500, "UpdateUser", err) + ctx.ServerError("UpdateUser", err) return } diff --git a/routers/user/auth_openid.go b/routers/user/auth_openid.go index a5124680dd..c784d7e1e2 100644 --- a/routers/user/auth_openid.go +++ b/routers/user/auth_openid.go @@ -37,7 +37,7 @@ func SignInOpenID(ctx *context.Context) { // Check auto-login. isSucceed, err := AutoSignIn(ctx) if err != nil { - ctx.Handle(500, "AutoSignIn", err) + ctx.ServerError("AutoSignIn", err) return } @@ -276,7 +276,7 @@ func ConnectOpenIDPost(ctx *context.Context, form auth.ConnectOpenIDForm) { if models.IsErrUserNotExist(err) { ctx.RenderWithErr(ctx.Tr("form.username_password_incorrect"), tplConnectOID, &form) } else { - ctx.Handle(500, "ConnectOpenIDPost", err) + ctx.ServerError("ConnectOpenIDPost", err) } return } @@ -288,7 +288,7 @@ func ConnectOpenIDPost(ctx *context.Context, form auth.ConnectOpenIDForm) { ctx.RenderWithErr(ctx.Tr("form.openid_been_used", oid), tplConnectOID, &form) return } - ctx.Handle(500, "AddUserOpenID", err) + ctx.ServerError("AddUserOpenID", err) return } @@ -376,7 +376,7 @@ func RegisterOpenIDPost(ctx *context.Context, cpt *captcha.Captcha, form auth.Si ctx.Data["Err_UserName"] = true ctx.RenderWithErr(ctx.Tr("user.form.name_pattern_not_allowed", err.(models.ErrNamePatternNotAllowed).Pattern), tplSignUpOID, &form) default: - ctx.Handle(500, "CreateUser", err) + ctx.ServerError("CreateUser", err) } return } @@ -389,7 +389,7 @@ func RegisterOpenIDPost(ctx *context.Context, cpt *captcha.Captcha, form auth.Si ctx.RenderWithErr(ctx.Tr("form.openid_been_used", oid), tplSignUpOID, &form) return } - ctx.Handle(500, "AddUserOpenID", err) + ctx.ServerError("AddUserOpenID", err) return } @@ -399,7 +399,7 @@ func RegisterOpenIDPost(ctx *context.Context, cpt *captcha.Captcha, form auth.Si u.IsActive = true u.SetLastLogin() if err := models.UpdateUserCols(u, "is_admin", "is_active", "last_login_unix"); err != nil { - ctx.Handle(500, "UpdateUser", err) + ctx.ServerError("UpdateUser", err) return } } diff --git a/routers/user/home.go b/routers/user/home.go index 9d42bb0ae6..5687cb4f1a 100644 --- a/routers/user/home.go +++ b/routers/user/home.go @@ -35,9 +35,9 @@ func getDashboardContextUser(ctx *context.Context) *models.User { org, err := models.GetUserByName(orgName) if err != nil { if models.IsErrUserNotExist(err) { - ctx.Handle(404, "GetUserByName", err) + ctx.NotFound("GetUserByName", err) } else { - ctx.Handle(500, "GetUserByName", err) + ctx.ServerError("GetUserByName", err) } return nil } @@ -46,7 +46,7 @@ func getDashboardContextUser(ctx *context.Context) *models.User { ctx.Data["ContextUser"] = ctxUser if err := ctx.User.GetOrganizations(true); err != nil { - ctx.Handle(500, "GetOrganizations", err) + ctx.ServerError("GetOrganizations", err) return nil } ctx.Data["Orgs"] = ctx.User.Orgs @@ -58,7 +58,7 @@ func getDashboardContextUser(ctx *context.Context) *models.User { func retrieveFeeds(ctx *context.Context, options models.GetFeedsOptions) { actions, err := models.GetFeeds(options) if err != nil { - ctx.Handle(500, "GetFeeds", err) + ctx.ServerError("GetFeeds", err) return } @@ -76,7 +76,7 @@ func retrieveFeeds(ctx *context.Context, options models.GetFeedsOptions) { if models.IsErrUserNotExist(err) { continue } - ctx.Handle(500, "GetUserByID", err) + ctx.ServerError("GetUserByID", err) return } userCache[act.ActUserID] = u @@ -90,7 +90,7 @@ func retrieveFeeds(ctx *context.Context, options models.GetFeedsOptions) { if models.IsErrRepoNotExist(err) { continue } - ctx.Handle(500, "GetRepositoryByID", err) + ctx.ServerError("GetRepositoryByID", err) return } } @@ -103,7 +103,7 @@ func retrieveFeeds(ctx *context.Context, options models.GetFeedsOptions) { if models.IsErrUserNotExist(err) { continue } - ctx.Handle(500, "GetUserByID", err) + ctx.ServerError("GetUserByID", err) return } } @@ -129,26 +129,26 @@ func Dashboard(ctx *context.Context) { if ctxUser.IsOrganization() { env, err := ctxUser.AccessibleReposEnv(ctx.User.ID) if err != nil { - ctx.Handle(500, "AccessibleReposEnv", err) + ctx.ServerError("AccessibleReposEnv", err) return } mirrors, err = env.MirrorRepos() if err != nil { - ctx.Handle(500, "env.MirrorRepos", err) + ctx.ServerError("env.MirrorRepos", err) return } } else { mirrors, err = ctxUser.GetMirrorRepositories() if err != nil { - ctx.Handle(500, "GetMirrorRepositories", err) + ctx.ServerError("GetMirrorRepositories", err) return } } ctx.Data["MaxShowRepoNum"] = setting.UI.User.RepoPagingNum if err := models.MirrorRepositoryList(mirrors).LoadAttributes(); err != nil { - ctx.Handle(500, "MirrorRepositoryList.LoadAttributes", err) + ctx.ServerError("MirrorRepositoryList.LoadAttributes", err) return } ctx.Data["MirrorCount"] = len(mirrors) @@ -217,18 +217,18 @@ func Issues(ctx *context.Context) { if ctxUser.IsOrganization() { env, err := ctxUser.AccessibleReposEnv(ctx.User.ID) if err != nil { - ctx.Handle(500, "AccessibleReposEnv", err) + ctx.ServerError("AccessibleReposEnv", err) return } userRepoIDs, err = env.RepoIDs(1, ctxUser.NumRepos) if err != nil { - ctx.Handle(500, "env.RepoIDs", err) + ctx.ServerError("env.RepoIDs", err) return } } else { userRepoIDs, err = ctxUser.GetAccessRepoIDs() if err != nil { - ctx.Handle(500, "ctxUser.GetAccessRepoIDs", err) + ctx.ServerError("ctxUser.GetAccessRepoIDs", err) return } } @@ -266,7 +266,7 @@ func Issues(ctx *context.Context) { counts, err := models.CountIssuesByRepo(opts) if err != nil { - ctx.Handle(500, "CountIssuesByRepo", err) + ctx.ServerError("CountIssuesByRepo", err) return } @@ -274,7 +274,7 @@ func Issues(ctx *context.Context) { opts.PageSize = setting.UI.IssuePagingNum issues, err := models.Issues(opts) if err != nil { - ctx.Handle(500, "Issues", err) + ctx.ServerError("Issues", err) return } @@ -282,7 +282,7 @@ func Issues(ctx *context.Context) { for repoID := range counts { repo, err := models.GetRepositoryByID(repoID) if err != nil { - ctx.Handle(500, "GetRepositoryByID", err) + ctx.ServerError("GetRepositoryByID", err) return } showReposMap[repoID] = repo @@ -292,7 +292,7 @@ func Issues(ctx *context.Context) { if _, ok := showReposMap[repoID]; !ok { repo, err := models.GetRepositoryByID(repoID) if err != nil { - ctx.Handle(500, "GetRepositoryByID", fmt.Errorf("[%d]%v", repoID, err)) + ctx.ServerError("GetRepositoryByID", fmt.Errorf("[%d]%v", repoID, err)) return } showReposMap[repoID] = repo @@ -310,7 +310,7 @@ func Issues(ctx *context.Context) { showRepos := models.RepositoryListOfMap(showReposMap) sort.Sort(showRepos) if err = showRepos.LoadAttributes(); err != nil { - ctx.Handle(500, "LoadAttributes", err) + ctx.ServerError("LoadAttributes", err) return } @@ -327,7 +327,7 @@ func Issues(ctx *context.Context) { IsClosed: isShowClosed, }) if err != nil { - ctx.Handle(500, "GetUserIssueStats", err) + ctx.ServerError("GetUserIssueStats", err) return } @@ -361,7 +361,7 @@ func Issues(ctx *context.Context) { func ShowSSHKeys(ctx *context.Context, uid int64) { keys, err := models.ListPublicKeys(uid) if err != nil { - ctx.Handle(500, "ListPublicKeys", err) + ctx.ServerError("ListPublicKeys", err) return } @@ -396,17 +396,17 @@ func showOrgProfile(ctx *context.Context) { if ctx.IsSigned && !ctx.User.IsAdmin { env, err := org.AccessibleReposEnv(ctx.User.ID) if err != nil { - ctx.Handle(500, "AccessibleReposEnv", err) + ctx.ServerError("AccessibleReposEnv", err) return } repos, err = env.Repos(page, setting.UI.User.RepoPagingNum) if err != nil { - ctx.Handle(500, "env.Repos", err) + ctx.ServerError("env.Repos", err) return } count, err = env.CountRepos() if err != nil { - ctx.Handle(500, "env.CountRepos", err) + ctx.ServerError("env.CountRepos", err) return } ctx.Data["Repos"] = repos @@ -414,7 +414,7 @@ func showOrgProfile(ctx *context.Context) { showPrivate := ctx.IsSigned && ctx.User.IsAdmin repos, err = models.GetUserRepositories(org.ID, showPrivate, page, setting.UI.User.RepoPagingNum, "") if err != nil { - ctx.Handle(500, "GetRepositories", err) + ctx.ServerError("GetRepositories", err) return } ctx.Data["Repos"] = repos @@ -423,7 +423,7 @@ func showOrgProfile(ctx *context.Context) { ctx.Data["Page"] = paginater.New(int(count), setting.UI.User.RepoPagingNum, page, 5) if err := org.GetMembers(); err != nil { - ctx.Handle(500, "GetMembers", err) + ctx.ServerError("GetMembers", err) return } ctx.Data["Members"] = org.Members @@ -438,9 +438,9 @@ func Email2User(ctx *context.Context) { u, err := models.GetUserByEmail(ctx.Query("email")) if err != nil { if models.IsErrUserNotExist(err) { - ctx.Handle(404, "GetUserByEmail", err) + ctx.NotFound("GetUserByEmail", err) } else { - ctx.Handle(500, "GetUserByEmail", err) + ctx.ServerError("GetUserByEmail", err) } return } diff --git a/routers/user/notification.go b/routers/user/notification.go index c7f23afe69..32cacdd2c4 100644 --- a/routers/user/notification.go +++ b/routers/user/notification.go @@ -30,7 +30,7 @@ func GetNotificationCount(c *context.Context) { count, err := models.GetNotificationCount(c.User, models.NotificationStatusUnread) if err != nil { - c.Handle(500, "GetNotificationCount", err) + c.ServerError("GetNotificationCount", err) return } @@ -62,13 +62,13 @@ func Notifications(c *context.Context) { statuses := []models.NotificationStatus{status, models.NotificationStatusPinned} notifications, err := models.NotificationsForUser(c.User, statuses, page, perPage) if err != nil { - c.Handle(500, "ErrNotificationsForUser", err) + c.ServerError("ErrNotificationsForUser", err) return } total, err := models.GetNotificationCount(c.User, status) if err != nil { - c.Handle(500, "ErrGetNotificationCount", err) + c.ServerError("ErrGetNotificationCount", err) return } @@ -100,12 +100,12 @@ func NotificationStatusPost(c *context.Context) { case "pinned": status = models.NotificationStatusPinned default: - c.Handle(500, "InvalidNotificationStatus", errors.New("Invalid notification status")) + c.ServerError("InvalidNotificationStatus", errors.New("Invalid notification status")) return } if err := models.SetNotificationStatus(notificationID, c.User, status); err != nil { - c.Handle(500, "SetNotificationStatus", err) + c.ServerError("SetNotificationStatus", err) return } @@ -117,7 +117,7 @@ func NotificationStatusPost(c *context.Context) { func NotificationPurgePost(c *context.Context) { err := models.UpdateNotificationStatuses(c.User, models.NotificationStatusUnread, models.NotificationStatusRead) if err != nil { - c.Handle(500, "ErrUpdateNotificationStatuses", err) + c.ServerError("ErrUpdateNotificationStatuses", err) return } diff --git a/routers/user/profile.go b/routers/user/profile.go index 86819de251..d63f84afd3 100644 --- a/routers/user/profile.go +++ b/routers/user/profile.go @@ -29,9 +29,9 @@ func GetUserByName(ctx *context.Context, name string) *models.User { user, err := models.GetUserByName(name) if err != nil { if models.IsErrUserNotExist(err) { - ctx.Handle(404, "GetUserByName", nil) + ctx.NotFound("GetUserByName", nil) } else { - ctx.Handle(500, "GetUserByName", err) + ctx.ServerError("GetUserByName", err) } return nil } @@ -79,7 +79,7 @@ func Profile(ctx *context.Context) { // Show OpenID URIs openIDs, err := models.GetUserOpenIDs(ctxUser.ID) if err != nil { - ctx.Handle(500, "GetUserOpenIDs", err) + ctx.ServerError("GetUserOpenIDs", err) return } @@ -91,7 +91,7 @@ func Profile(ctx *context.Context) { orgs, err := models.GetOrgsByUserID(ctxUser.ID, showPrivate) if err != nil { - ctx.Handle(500, "GetOrgsByUserIDDesc", err) + ctx.ServerError("GetOrgsByUserIDDesc", err) return } @@ -147,13 +147,13 @@ func Profile(ctx *context.Context) { if len(keyword) == 0 { repos, err = ctxUser.GetStarredRepos(showPrivate, page, setting.UI.User.RepoPagingNum, orderBy.String()) if err != nil { - ctx.Handle(500, "GetStarredRepos", err) + ctx.ServerError("GetStarredRepos", err) return } count, err = ctxUser.GetStarredRepoCount(showPrivate) if err != nil { - ctx.Handle(500, "GetStarredRepoCount", err) + ctx.ServerError("GetStarredRepoCount", err) return } } else { @@ -168,7 +168,7 @@ func Profile(ctx *context.Context) { Collaborate: util.OptionalBoolFalse, }) if err != nil { - ctx.Handle(500, "SearchRepositoryByName", err) + ctx.ServerError("SearchRepositoryByName", err) return } } @@ -181,7 +181,7 @@ func Profile(ctx *context.Context) { var total int repos, err = models.GetUserRepositories(ctxUser.ID, showPrivate, page, setting.UI.User.RepoPagingNum, orderBy.String()) if err != nil { - ctx.Handle(500, "GetRepositories", err) + ctx.ServerError("GetRepositories", err) return } ctx.Data["Repos"] = repos @@ -191,7 +191,7 @@ func Profile(ctx *context.Context) { } else { count, err := models.GetPublicRepositoryCount(ctxUser) if err != nil { - ctx.Handle(500, "GetPublicRepositoryCount", err) + ctx.ServerError("GetPublicRepositoryCount", err) return } total = int(count) @@ -210,7 +210,7 @@ func Profile(ctx *context.Context) { PageSize: setting.UI.User.RepoPagingNum, }) if err != nil { - ctx.Handle(500, "SearchRepositoryByName", err) + ctx.ServerError("SearchRepositoryByName", err) return } @@ -267,7 +267,7 @@ func Action(ctx *context.Context) { } if err != nil { - ctx.Handle(500, fmt.Sprintf("Action (%s)", ctx.Params(":action")), err) + ctx.ServerError(fmt.Sprintf("Action (%s)", ctx.Params(":action")), err) return } diff --git a/routers/user/setting.go b/routers/user/setting.go index d83c62d89d..dcd0eedb8d 100644 --- a/routers/user/setting.go +++ b/routers/user/setting.go @@ -73,7 +73,7 @@ func handleUsernameChange(ctx *context.Context, newName string) { ctx.Flash.Error(ctx.Tr("user.newName_pattern_not_allowed")) ctx.Redirect(setting.AppSubURL + "/user/settings") default: - ctx.Handle(500, "ChangeUserName", err) + ctx.ServerError("ChangeUserName", err) } return } @@ -111,7 +111,7 @@ func SettingsPost(ctx *context.Context, form auth.UpdateProfileForm) { ctx.Redirect(setting.AppSubURL + "/user/settings") return } - ctx.Handle(500, "UpdateUser", err) + ctx.ServerError("UpdateUser", err) return } @@ -202,7 +202,7 @@ func SettingsSecurity(ctx *context.Context) { if models.IsErrTwoFactorNotEnrolled(err) { enrolled = false } else { - ctx.Handle(500, "SettingsTwoFactor", err) + ctx.ServerError("SettingsTwoFactor", err) return } } @@ -232,12 +232,12 @@ func SettingsSecurityPost(ctx *context.Context, form auth.ChangePasswordForm) { ctx.User.Passwd = form.Password var err error if ctx.User.Salt, err = models.GetUserSalt(); err != nil { - ctx.Handle(500, "UpdateUser", err) + ctx.ServerError("UpdateUser", err) return } ctx.User.HashPassword() if err := models.UpdateUserCols(ctx.User, "salt", "passwd"); err != nil { - ctx.Handle(500, "UpdateUser", err) + ctx.ServerError("UpdateUser", err) return } log.Trace("User password updated: %s", ctx.User.Name) @@ -254,7 +254,7 @@ func SettingsEmails(ctx *context.Context) { emails, err := models.GetEmailAddresses(ctx.User.ID) if err != nil { - ctx.Handle(500, "GetEmailAddresses", err) + ctx.ServerError("GetEmailAddresses", err) return } ctx.Data["Emails"] = emails @@ -270,7 +270,7 @@ func SettingsEmailPost(ctx *context.Context, form auth.AddEmailForm) { // Make emailaddress primary. if ctx.Query("_method") == "PRIMARY" { if err := models.MakeEmailPrimary(&models.EmailAddress{ID: ctx.QueryInt64("id")}); err != nil { - ctx.Handle(500, "MakeEmailPrimary", err) + ctx.ServerError("MakeEmailPrimary", err) return } @@ -282,7 +282,7 @@ func SettingsEmailPost(ctx *context.Context, form auth.AddEmailForm) { // Add Email address. emails, err := models.GetEmailAddresses(ctx.User.ID) if err != nil { - ctx.Handle(500, "GetEmailAddresses", err) + ctx.ServerError("GetEmailAddresses", err) return } ctx.Data["Emails"] = emails @@ -302,7 +302,7 @@ func SettingsEmailPost(ctx *context.Context, form auth.AddEmailForm) { ctx.RenderWithErr(ctx.Tr("form.email_been_used"), tplSettingsEmails, &form) return } - ctx.Handle(500, "AddEmailAddress", err) + ctx.ServerError("AddEmailAddress", err) return } @@ -325,7 +325,7 @@ func SettingsEmailPost(ctx *context.Context, form auth.AddEmailForm) { // DeleteEmail response for delete user's email func DeleteEmail(ctx *context.Context) { if err := models.DeleteEmailAddress(&models.EmailAddress{ID: ctx.QueryInt64("id"), UID: ctx.User.ID}); err != nil { - ctx.Handle(500, "DeleteEmail", err) + ctx.ServerError("DeleteEmail", err) return } log.Trace("Email address deleted: %s", ctx.User.Name) @@ -344,14 +344,14 @@ func SettingsKeys(ctx *context.Context) { keys, err := models.ListPublicKeys(ctx.User.ID) if err != nil { - ctx.Handle(500, "ListPublicKeys", err) + ctx.ServerError("ListPublicKeys", err) return } ctx.Data["Keys"] = keys gpgkeys, err := models.ListGPGKeys(ctx.User.ID) if err != nil { - ctx.Handle(500, "ListGPGKeys", err) + ctx.ServerError("ListGPGKeys", err) return } ctx.Data["GPGKeys"] = gpgkeys @@ -366,14 +366,14 @@ func SettingsKeysPost(ctx *context.Context, form auth.AddKeyForm) { keys, err := models.ListPublicKeys(ctx.User.ID) if err != nil { - ctx.Handle(500, "ListPublicKeys", err) + ctx.ServerError("ListPublicKeys", err) return } ctx.Data["Keys"] = keys gpgkeys, err := models.ListGPGKeys(ctx.User.ID) if err != nil { - ctx.Handle(500, "ListGPGKeys", err) + ctx.ServerError("ListGPGKeys", err) return } ctx.Data["GPGKeys"] = gpgkeys @@ -398,7 +398,7 @@ func SettingsKeysPost(ctx *context.Context, form auth.AddKeyForm) { ctx.Data["Err_Content"] = true ctx.RenderWithErr(ctx.Tr("settings.gpg_no_key_email_found"), tplSettingsKeys, &form) default: - ctx.Handle(500, "AddPublicKey", err) + ctx.ServerError("AddPublicKey", err) } return } @@ -428,7 +428,7 @@ func SettingsKeysPost(ctx *context.Context, form auth.AddKeyForm) { ctx.Data["Err_Title"] = true ctx.RenderWithErr(ctx.Tr("settings.ssh_key_name_used"), tplSettingsKeys, &form) default: - ctx.Handle(500, "AddPublicKey", err) + ctx.ServerError("AddPublicKey", err) } return } @@ -474,7 +474,7 @@ func SettingsApplications(ctx *context.Context) { tokens, err := models.ListAccessTokens(ctx.User.ID) if err != nil { - ctx.Handle(500, "ListAccessTokens", err) + ctx.ServerError("ListAccessTokens", err) return } ctx.Data["Tokens"] = tokens @@ -490,7 +490,7 @@ func SettingsApplicationsPost(ctx *context.Context, form auth.NewAccessTokenForm if ctx.HasError() { tokens, err := models.ListAccessTokens(ctx.User.ID) if err != nil { - ctx.Handle(500, "ListAccessTokens", err) + ctx.ServerError("ListAccessTokens", err) return } ctx.Data["Tokens"] = tokens @@ -503,7 +503,7 @@ func SettingsApplicationsPost(ctx *context.Context, form auth.NewAccessTokenForm Name: form.Name, } if err := models.NewAccessToken(t); err != nil { - ctx.Handle(500, "NewAccessToken", err) + ctx.ServerError("NewAccessToken", err) return } @@ -533,17 +533,17 @@ func SettingsTwoFactorRegenerateScratch(ctx *context.Context) { t, err := models.GetTwoFactorByUID(ctx.User.ID) if err != nil { - ctx.Handle(500, "SettingsTwoFactor", err) + ctx.ServerError("SettingsTwoFactor", err) return } if err = t.GenerateScratchToken(); err != nil { - ctx.Handle(500, "SettingsTwoFactor", err) + ctx.ServerError("SettingsTwoFactor", err) return } if err = models.UpdateTwoFactor(t); err != nil { - ctx.Handle(500, "SettingsTwoFactor", err) + ctx.ServerError("SettingsTwoFactor", err) return } @@ -558,12 +558,12 @@ func SettingsTwoFactorDisable(ctx *context.Context) { t, err := models.GetTwoFactorByUID(ctx.User.ID) if err != nil { - ctx.Handle(500, "SettingsTwoFactor", err) + ctx.ServerError("SettingsTwoFactor", err) return } if err = models.DeleteTwoFactorByID(t.ID, ctx.User.ID); err != nil { - ctx.Handle(500, "SettingsTwoFactor", err) + ctx.ServerError("SettingsTwoFactor", err) return } @@ -585,7 +585,7 @@ func twofaGenerateSecretAndQr(ctx *context.Context) bool { AccountName: ctx.User.Name, }) if err != nil { - ctx.Handle(500, "SettingsTwoFactor", err) + ctx.ServerError("SettingsTwoFactor", err) return false } } @@ -593,13 +593,13 @@ func twofaGenerateSecretAndQr(ctx *context.Context) bool { ctx.Data["TwofaSecret"] = otpKey.Secret() img, err := otpKey.Image(320, 240) if err != nil { - ctx.Handle(500, "SettingsTwoFactor", err) + ctx.ServerError("SettingsTwoFactor", err) return false } var imgBytes bytes.Buffer if err = png.Encode(&imgBytes, img); err != nil { - ctx.Handle(500, "SettingsTwoFactor", err) + ctx.ServerError("SettingsTwoFactor", err) return false } @@ -617,11 +617,11 @@ func SettingsTwoFactorEnroll(ctx *context.Context) { t, err := models.GetTwoFactorByUID(ctx.User.ID) if t != nil { // already enrolled - ctx.Handle(500, "SettingsTwoFactor", err) + ctx.ServerError("SettingsTwoFactor", err) return } if err != nil && !models.IsErrTwoFactorNotEnrolled(err) { - ctx.Handle(500, "SettingsTwoFactor", err) + ctx.ServerError("SettingsTwoFactor", err) return } @@ -640,11 +640,11 @@ func SettingsTwoFactorEnrollPost(ctx *context.Context, form auth.TwoFactorAuthFo t, err := models.GetTwoFactorByUID(ctx.User.ID) if t != nil { // already enrolled - ctx.Handle(500, "SettingsTwoFactor", err) + ctx.ServerError("SettingsTwoFactor", err) return } if err != nil && !models.IsErrTwoFactorNotEnrolled(err) { - ctx.Handle(500, "SettingsTwoFactor", err) + ctx.ServerError("SettingsTwoFactor", err) return } @@ -671,17 +671,17 @@ func SettingsTwoFactorEnrollPost(ctx *context.Context, form auth.TwoFactorAuthFo } err = t.SetSecret(secret) if err != nil { - ctx.Handle(500, "SettingsTwoFactor", err) + ctx.ServerError("SettingsTwoFactor", err) return } err = t.GenerateScratchToken() if err != nil { - ctx.Handle(500, "SettingsTwoFactor", err) + ctx.ServerError("SettingsTwoFactor", err) return } if err = models.NewTwoFactor(t); err != nil { - ctx.Handle(500, "SettingsTwoFactor", err) + ctx.ServerError("SettingsTwoFactor", err) return } @@ -698,7 +698,7 @@ func SettingsAccountLinks(ctx *context.Context) { accountLinks, err := models.ListAccountLinks(ctx.User) if err != nil { - ctx.Handle(500, "ListAccountLinks", err) + ctx.ServerError("ListAccountLinks", err) return } @@ -745,7 +745,7 @@ func SettingsDelete(ctx *context.Context) { if models.IsErrUserNotExist(err) { ctx.RenderWithErr(ctx.Tr("form.enterred_invalid_password"), tplSettingsDelete, nil) } else { - ctx.Handle(500, "UserSignIn", err) + ctx.ServerError("UserSignIn", err) } return } @@ -759,7 +759,7 @@ func SettingsDelete(ctx *context.Context) { ctx.Flash.Error(ctx.Tr("form.still_has_org")) ctx.Redirect(setting.AppSubURL + "/user/settings/delete") default: - ctx.Handle(500, "DeleteUser", err) + ctx.ServerError("DeleteUser", err) } } else { log.Trace("Account deleted: %s", ctx.User.Name) @@ -777,7 +777,7 @@ func SettingsOrganization(ctx *context.Context) { ctx.Data["PageIsSettingsOrganization"] = true orgs, err := models.GetOrgsByUserID(ctx.User.ID, ctx.IsSigned) if err != nil { - ctx.Handle(500, "GetOrgsByUserID", err) + ctx.ServerError("GetOrgsByUserID", err) return } ctx.Data["Orgs"] = orgs @@ -792,7 +792,7 @@ func SettingsRepos(ctx *context.Context) { var err error if err = ctxUser.GetRepositories(1, setting.UI.User.RepoPagingNum); err != nil { - ctx.Handle(500, "GetRepositories", err) + ctx.ServerError("GetRepositories", err) return } repos := ctxUser.Repos @@ -801,12 +801,12 @@ func SettingsRepos(ctx *context.Context) { if repos[i].IsFork { err := repos[i].GetBaseRepo() if err != nil { - ctx.Handle(500, "GetBaseRepo", err) + ctx.ServerError("GetBaseRepo", err) return } err = repos[i].BaseRepo.GetOwner() if err != nil { - ctx.Handle(500, "GetOwner", err) + ctx.ServerError("GetOwner", err) return } } diff --git a/routers/user/setting_openid.go b/routers/user/setting_openid.go index b39278d7c3..92eb636e29 100644 --- a/routers/user/setting_openid.go +++ b/routers/user/setting_openid.go @@ -30,7 +30,7 @@ func SettingsOpenID(ctx *context.Context) { openid, err := models.GetUserOpenIDs(ctx.User.ID) if err != nil { - ctx.Handle(500, "GetUserOpenIDs", err) + ctx.ServerError("GetUserOpenIDs", err) return } ctx.Data["OpenIDs"] = openid @@ -46,7 +46,7 @@ func SettingsOpenIDPost(ctx *context.Context, form auth.AddOpenIDForm) { if ctx.HasError() { openid, err := models.GetUserOpenIDs(ctx.User.ID) if err != nil { - ctx.Handle(500, "GetUserOpenIDs", err) + ctx.ServerError("GetUserOpenIDs", err) return } ctx.Data["OpenIDs"] = openid @@ -70,7 +70,7 @@ func SettingsOpenIDPost(ctx *context.Context, form auth.AddOpenIDForm) { oids, err := models.GetUserOpenIDs(ctx.User.ID) if err != nil { - ctx.Handle(500, "GetUserOpenIDs", err) + ctx.ServerError("GetUserOpenIDs", err) return } ctx.Data["OpenIDs"] = oids @@ -100,7 +100,7 @@ func settingsOpenIDVerify(ctx *context.Context) { oids, err := models.GetUserOpenIDs(ctx.User.ID) if err != nil { - ctx.Handle(500, "GetUserOpenIDs", err) + ctx.ServerError("GetUserOpenIDs", err) return } ctx.Data["OpenIDs"] = oids @@ -121,7 +121,7 @@ func settingsOpenIDVerify(ctx *context.Context) { ctx.RenderWithErr(ctx.Tr("form.openid_been_used", id), tplSettingsOpenID, &auth.AddOpenIDForm{Openid: id}) return } - ctx.Handle(500, "AddUserOpenID", err) + ctx.ServerError("AddUserOpenID", err) return } log.Trace("Associated OpenID %s to user %s", id, ctx.User.Name) @@ -133,7 +133,7 @@ func settingsOpenIDVerify(ctx *context.Context) { // DeleteOpenID response for delete user's openid func DeleteOpenID(ctx *context.Context) { if err := models.DeleteUserOpenID(&models.UserOpenID{ID: ctx.QueryInt64("id"), UID: ctx.User.ID}); err != nil { - ctx.Handle(500, "DeleteUserOpenID", err) + ctx.ServerError("DeleteUserOpenID", err) return } log.Trace("OpenID address deleted: %s", ctx.User.Name) @@ -147,7 +147,7 @@ func DeleteOpenID(ctx *context.Context) { // ToggleOpenIDVisibility response for toggle visibility of user's openid func ToggleOpenIDVisibility(ctx *context.Context) { if err := models.ToggleUserOpenIDVisibility(ctx.QueryInt64("id")); err != nil { - ctx.Handle(500, "ToggleUserOpenIDVisibility", err) + ctx.ServerError("ToggleUserOpenIDVisibility", err) return } |