Handle refactor (#3339)

* Replace all ctx.Handle with ctx.ServerError or ctx.NotFound

* Change Handle(403) to NotFound, avoid using macaron's NotFound
This commit is contained in:
Morgan Bazalgette 2018-01-10 22:34:17 +01:00 committed by Lauris BH
parent 45c264f681
commit 65861900cd
48 changed files with 622 additions and 610 deletions

View File

@ -5,7 +5,6 @@
package context package context
import ( import (
"fmt"
"html" "html"
"html/template" "html/template"
"io" "io"
@ -92,8 +91,8 @@ func (ctx *Context) RenderWithErr(msg string, tpl base.TplName, form interface{}
ctx.HTML(200, tpl) ctx.HTML(200, tpl)
} }
// Handle handles and logs error by given status. // NotFound displays a 404 (Not Found) page and prints the given error, if any.
func (ctx *Context) Handle(status int, title string, err error) { func (ctx *Context) NotFound(title string, err error) {
if err != nil { if err != nil {
log.Error(4, "%s: %v", title, err) log.Error(4, "%s: %v", title, err)
if macaron.Env != macaron.PROD { if macaron.Env != macaron.PROD {
@ -101,13 +100,22 @@ func (ctx *Context) Handle(status int, title string, err error) {
} }
} }
switch status {
case 404:
ctx.Data["Title"] = "Page Not Found" ctx.Data["Title"] = "Page Not Found"
case 500: ctx.HTML(http.StatusNotFound, base.TplName("status/404"))
ctx.Data["Title"] = "Internal Server Error" }
// ServerError displays a 500 (Internal Server Error) page and prints the given
// error, if any.
func (ctx *Context) ServerError(title string, err error) {
if err != nil {
log.Error(4, "%s: %v", title, err)
if macaron.Env != macaron.PROD {
ctx.Data["ErrorMsg"] = err
} }
ctx.HTML(status, base.TplName(fmt.Sprintf("status/%d", status))) }
ctx.Data["Title"] = "Internal Server Error"
ctx.HTML(404, base.TplName("status/500"))
} }
// NotFoundOrServerError use error check function to determine if the error // NotFoundOrServerError use error check function to determine if the error
@ -115,11 +123,11 @@ func (ctx *Context) Handle(status int, title string, err error) {
// or error context description for logging purpose of 500 server error. // or error context description for logging purpose of 500 server error.
func (ctx *Context) NotFoundOrServerError(title string, errck func(error) bool, err error) { func (ctx *Context) NotFoundOrServerError(title string, errck func(error) bool, err error) {
if errck(err) { if errck(err) {
ctx.Handle(404, title, err) ctx.NotFound(title, err)
return return
} }
ctx.Handle(500, title, err) ctx.ServerError(title, err)
} }
// HandleText handles HTTP status code // HandleText handles HTTP status code
@ -218,7 +226,7 @@ func Contexter() macaron.Handler {
// If request sends files, parse them here otherwise the Query() can't be parsed and the CsrfToken will be invalid. // If request sends files, parse them here otherwise the Query() can't be parsed and the CsrfToken will be invalid.
if ctx.Req.Method == "POST" && strings.Contains(ctx.Req.Header.Get("Content-Type"), "multipart/form-data") { if ctx.Req.Method == "POST" && strings.Contains(ctx.Req.Header.Get("Content-Type"), "multipart/form-data") {
if err := ctx.Req.ParseMultipartForm(setting.AttachmentMaxSize << 20); err != nil && !strings.Contains(err.Error(), "EOF") { // 32MB max size if err := ctx.Req.ParseMultipartForm(setting.AttachmentMaxSize << 20); err != nil && !strings.Contains(err.Error(), "EOF") { // 32MB max size
ctx.Handle(500, "ParseMultipartForm", err) ctx.ServerError("ParseMultipartForm", err)
return return
} }
} }

View File

@ -51,9 +51,9 @@ func HandleOrgAssignment(ctx *Context, args ...bool) {
ctx.Org.Organization, err = models.GetUserByName(orgName) ctx.Org.Organization, err = models.GetUserByName(orgName)
if err != nil { if err != nil {
if models.IsErrUserNotExist(err) { if models.IsErrUserNotExist(err) {
ctx.Handle(404, "GetUserByName", err) ctx.NotFound("GetUserByName", err)
} else { } else {
ctx.Handle(500, "GetUserByName", err) ctx.ServerError("GetUserByName", err)
} }
return return
} }
@ -75,7 +75,7 @@ func HandleOrgAssignment(ctx *Context, args ...bool) {
} else if ctx.IsSigned { } else if ctx.IsSigned {
ctx.Org.IsOwner, err = org.IsOwnedBy(ctx.User.ID) ctx.Org.IsOwner, err = org.IsOwnedBy(ctx.User.ID)
if err != nil { if err != nil {
ctx.Handle(500, "IsOwnedBy", err) ctx.ServerError("IsOwnedBy", err)
return return
} }
@ -86,7 +86,7 @@ func HandleOrgAssignment(ctx *Context, args ...bool) {
} else { } else {
ctx.Org.IsMember, err = org.IsOrgMember(ctx.User.ID) ctx.Org.IsMember, err = org.IsOrgMember(ctx.User.ID)
if err != nil { if err != nil {
ctx.Handle(500, "IsOrgMember", err) ctx.ServerError("IsOrgMember", err)
return return
} }
} }
@ -96,7 +96,7 @@ func HandleOrgAssignment(ctx *Context, args ...bool) {
} }
if (requireMember && !ctx.Org.IsMember) || if (requireMember && !ctx.Org.IsMember) ||
(requireOwner && !ctx.Org.IsOwner) { (requireOwner && !ctx.Org.IsOwner) {
ctx.Handle(404, "OrgAssignment", err) ctx.NotFound("OrgAssignment", err)
return return
} }
ctx.Data["IsOrganizationOwner"] = ctx.Org.IsOwner ctx.Data["IsOrganizationOwner"] = ctx.Org.IsOwner
@ -109,13 +109,13 @@ func HandleOrgAssignment(ctx *Context, args ...bool) {
if ctx.Org.IsMember { if ctx.Org.IsMember {
if ctx.Org.IsOwner { if ctx.Org.IsOwner {
if err := org.GetTeams(); err != nil { if err := org.GetTeams(); err != nil {
ctx.Handle(500, "GetTeams", err) ctx.ServerError("GetTeams", err)
return return
} }
} else { } else {
org.Teams, err = org.GetUserTeams(ctx.User.ID) org.Teams, err = org.GetUserTeams(ctx.User.ID)
if err != nil { if err != nil {
ctx.Handle(500, "GetUserTeams", err) ctx.ServerError("GetUserTeams", err)
return return
} }
} }
@ -135,20 +135,20 @@ func HandleOrgAssignment(ctx *Context, args ...bool) {
} }
if !teamExists { if !teamExists {
ctx.Handle(404, "OrgAssignment", err) ctx.NotFound("OrgAssignment", err)
return return
} }
ctx.Data["IsTeamMember"] = ctx.Org.IsTeamMember ctx.Data["IsTeamMember"] = ctx.Org.IsTeamMember
if requireTeamMember && !ctx.Org.IsTeamMember { if requireTeamMember && !ctx.Org.IsTeamMember {
ctx.Handle(404, "OrgAssignment", err) ctx.NotFound("OrgAssignment", err)
return return
} }
ctx.Org.IsTeamAdmin = ctx.Org.Team.IsOwnerTeam() || ctx.Org.Team.Authorize >= models.AccessModeAdmin ctx.Org.IsTeamAdmin = ctx.Org.Team.IsOwnerTeam() || ctx.Org.Team.Authorize >= models.AccessModeAdmin
ctx.Data["IsTeamAdmin"] = ctx.Org.IsTeamAdmin ctx.Data["IsTeamAdmin"] = ctx.Org.IsTeamAdmin
if requireTeamAdmin && !ctx.Org.IsTeamAdmin { if requireTeamAdmin && !ctx.Org.IsTeamAdmin {
ctx.Handle(404, "OrgAssignment", err) ctx.NotFound("OrgAssignment", err)
return return
} }
} }

View File

@ -166,10 +166,10 @@ func RetrieveBaseRepo(ctx *Context, repo *models.Repository) {
repo.ForkID = 0 repo.ForkID = 0
return return
} }
ctx.Handle(500, "GetBaseRepo", err) ctx.ServerError("GetBaseRepo", err)
return return
} else if err = repo.BaseRepo.GetOwner(); err != nil { } else if err = repo.BaseRepo.GetOwner(); err != nil {
ctx.Handle(500, "BaseRepo.GetOwner", err) ctx.ServerError("BaseRepo.GetOwner", err)
return return
} }
} }
@ -201,7 +201,7 @@ func RedirectToRepo(ctx *Context, redirectRepoID int64) {
repo, err := models.GetRepositoryByID(redirectRepoID) repo, err := models.GetRepositoryByID(redirectRepoID)
if err != nil { if err != nil {
ctx.Handle(500, "GetRepositoryByID", err) ctx.ServerError("GetRepositoryByID", err)
return return
} }
@ -225,7 +225,7 @@ func repoAssignment(ctx *Context, repo *models.Repository) {
} }
mode, err := models.AccessLevel(userID, repo) mode, err := models.AccessLevel(userID, repo)
if err != nil { if err != nil {
ctx.Handle(500, "AccessLevel", err) ctx.ServerError("AccessLevel", err)
return return
} }
ctx.Repo.AccessMode = mode ctx.Repo.AccessMode = mode
@ -237,7 +237,7 @@ func repoAssignment(ctx *Context, repo *models.Repository) {
EarlyResponseForGoGetMeta(ctx) EarlyResponseForGoGetMeta(ctx)
return return
} }
ctx.Handle(404, "no access right", nil) ctx.NotFound("no access right", nil)
return return
} }
ctx.Data["HasAccess"] = true ctx.Data["HasAccess"] = true
@ -246,7 +246,7 @@ func repoAssignment(ctx *Context, repo *models.Repository) {
var err error var err error
ctx.Repo.Mirror, err = models.GetMirrorByRepoID(repo.ID) ctx.Repo.Mirror, err = models.GetMirrorByRepoID(repo.ID)
if err != nil { if err != nil {
ctx.Handle(500, "GetMirror", err) ctx.ServerError("GetMirror", err)
return return
} }
ctx.Data["MirrorEnablePrune"] = ctx.Repo.Mirror.EnablePrune ctx.Data["MirrorEnablePrune"] = ctx.Repo.Mirror.EnablePrune
@ -268,15 +268,15 @@ func RepoIDAssignment() macaron.Handler {
repo, err := models.GetRepositoryByID(repoID) repo, err := models.GetRepositoryByID(repoID)
if err != nil { if err != nil {
if models.IsErrRepoNotExist(err) { if models.IsErrRepoNotExist(err) {
ctx.Handle(404, "GetRepositoryByID", nil) ctx.NotFound("GetRepositoryByID", nil)
} else { } else {
ctx.Handle(500, "GetRepositoryByID", err) ctx.ServerError("GetRepositoryByID", err)
} }
return return
} }
if err = repo.GetOwner(); err != nil { if err = repo.GetOwner(); err != nil {
ctx.Handle(500, "GetOwner", err) ctx.ServerError("GetOwner", err)
return return
} }
repoAssignment(ctx, repo) repoAssignment(ctx, repo)
@ -305,9 +305,9 @@ func RepoAssignment() macaron.Handler {
EarlyResponseForGoGetMeta(ctx) EarlyResponseForGoGetMeta(ctx)
return return
} }
ctx.Handle(404, "GetUserByName", nil) ctx.NotFound("GetUserByName", nil)
} else { } else {
ctx.Handle(500, "GetUserByName", err) ctx.ServerError("GetUserByName", err)
} }
return return
} }
@ -327,12 +327,12 @@ func RepoAssignment() macaron.Handler {
EarlyResponseForGoGetMeta(ctx) EarlyResponseForGoGetMeta(ctx)
return return
} }
ctx.Handle(404, "GetRepositoryByName", nil) ctx.NotFound("GetRepositoryByName", nil)
} else { } else {
ctx.Handle(500, "LookupRepoRedirect", err) ctx.ServerError("LookupRepoRedirect", err)
} }
} else { } else {
ctx.Handle(500, "GetRepositoryByName", err) ctx.ServerError("GetRepositoryByName", err)
} }
return return
} }
@ -345,7 +345,7 @@ func RepoAssignment() macaron.Handler {
gitRepo, err := git.OpenRepository(models.RepoPath(userName, repoName)) gitRepo, err := git.OpenRepository(models.RepoPath(userName, repoName))
if err != nil { if err != nil {
ctx.Handle(500, "RepoAssignment Invalid repo "+models.RepoPath(userName, repoName), err) ctx.ServerError("RepoAssignment Invalid repo "+models.RepoPath(userName, repoName), err)
return return
} }
ctx.Repo.GitRepo = gitRepo ctx.Repo.GitRepo = gitRepo
@ -355,7 +355,7 @@ func RepoAssignment() macaron.Handler {
tags, err := ctx.Repo.GitRepo.GetTags() tags, err := ctx.Repo.GitRepo.GetTags()
if err != nil { if err != nil {
ctx.Handle(500, "GetTags", err) ctx.ServerError("GetTags", err)
return return
} }
ctx.Data["Tags"] = tags ctx.Data["Tags"] = tags
@ -365,7 +365,7 @@ func RepoAssignment() macaron.Handler {
IncludeTags: true, IncludeTags: true,
}) })
if err != nil { if err != nil {
ctx.Handle(500, "GetReleaseCountByRepoID", err) ctx.ServerError("GetReleaseCountByRepoID", err)
return return
} }
ctx.Repo.Repository.NumReleases = int(count) ctx.Repo.Repository.NumReleases = int(count)
@ -378,7 +378,7 @@ func RepoAssignment() macaron.Handler {
ctx.Data["IsRepositoryWriter"] = ctx.Repo.IsWriter() ctx.Data["IsRepositoryWriter"] = ctx.Repo.IsWriter()
if ctx.Data["CanSignedUserFork"], err = ctx.Repo.Repository.CanUserFork(ctx.User); err != nil { if ctx.Data["CanSignedUserFork"], err = ctx.Repo.Repository.CanUserFork(ctx.User); err != nil {
ctx.Handle(500, "CanUserFork", err) ctx.ServerError("CanUserFork", err)
return return
} }
@ -403,7 +403,7 @@ func RepoAssignment() macaron.Handler {
ctx.Data["TagName"] = ctx.Repo.TagName ctx.Data["TagName"] = ctx.Repo.TagName
brs, err := ctx.Repo.GitRepo.GetBranches() brs, err := ctx.Repo.GitRepo.GetBranches()
if err != nil { if err != nil {
ctx.Handle(500, "GetBranches", err) ctx.ServerError("GetBranches", err)
return return
} }
ctx.Data["Branches"] = brs ctx.Data["Branches"] = brs
@ -550,7 +550,7 @@ func RepoRefByType(refType RepoRefType) macaron.Handler {
repoPath := models.RepoPath(ctx.Repo.Owner.Name, ctx.Repo.Repository.Name) repoPath := models.RepoPath(ctx.Repo.Owner.Name, ctx.Repo.Repository.Name)
ctx.Repo.GitRepo, err = git.OpenRepository(repoPath) ctx.Repo.GitRepo, err = git.OpenRepository(repoPath)
if err != nil { if err != nil {
ctx.Handle(500, "RepoRef Invalid repo "+repoPath, err) ctx.ServerError("RepoRef Invalid repo "+repoPath, err)
return return
} }
} }
@ -562,19 +562,19 @@ func RepoRefByType(refType RepoRefType) macaron.Handler {
if !ctx.Repo.GitRepo.IsBranchExist(refName) { if !ctx.Repo.GitRepo.IsBranchExist(refName) {
brs, err := ctx.Repo.GitRepo.GetBranches() brs, err := ctx.Repo.GitRepo.GetBranches()
if err != nil { if err != nil {
ctx.Handle(500, "GetBranches", err) ctx.ServerError("GetBranches", err)
return return
} else if len(brs) == 0 { } else if len(brs) == 0 {
err = fmt.Errorf("No branches in non-bare repository %s", err = fmt.Errorf("No branches in non-bare repository %s",
ctx.Repo.GitRepo.Path) ctx.Repo.GitRepo.Path)
ctx.Handle(500, "GetBranches", err) ctx.ServerError("GetBranches", err)
return return
} }
refName = brs[0] refName = brs[0]
} }
ctx.Repo.Commit, err = ctx.Repo.GitRepo.GetBranchCommit(refName) ctx.Repo.Commit, err = ctx.Repo.GitRepo.GetBranchCommit(refName)
if err != nil { if err != nil {
ctx.Handle(500, "GetBranchCommit", err) ctx.ServerError("GetBranchCommit", err)
return return
} }
ctx.Repo.CommitID = ctx.Repo.Commit.ID.String() ctx.Repo.CommitID = ctx.Repo.Commit.ID.String()
@ -588,7 +588,7 @@ func RepoRefByType(refType RepoRefType) macaron.Handler {
ctx.Repo.Commit, err = ctx.Repo.GitRepo.GetBranchCommit(refName) ctx.Repo.Commit, err = ctx.Repo.GitRepo.GetBranchCommit(refName)
if err != nil { if err != nil {
ctx.Handle(500, "GetBranchCommit", err) ctx.ServerError("GetBranchCommit", err)
return return
} }
ctx.Repo.CommitID = ctx.Repo.Commit.ID.String() ctx.Repo.CommitID = ctx.Repo.Commit.ID.String()
@ -597,7 +597,7 @@ func RepoRefByType(refType RepoRefType) macaron.Handler {
ctx.Repo.IsViewTag = true ctx.Repo.IsViewTag = true
ctx.Repo.Commit, err = ctx.Repo.GitRepo.GetTagCommit(refName) ctx.Repo.Commit, err = ctx.Repo.GitRepo.GetTagCommit(refName)
if err != nil { if err != nil {
ctx.Handle(500, "GetTagCommit", err) ctx.ServerError("GetTagCommit", err)
return return
} }
ctx.Repo.CommitID = ctx.Repo.Commit.ID.String() ctx.Repo.CommitID = ctx.Repo.Commit.ID.String()
@ -607,11 +607,11 @@ func RepoRefByType(refType RepoRefType) macaron.Handler {
ctx.Repo.Commit, err = ctx.Repo.GitRepo.GetCommit(refName) ctx.Repo.Commit, err = ctx.Repo.GitRepo.GetCommit(refName)
if err != nil { if err != nil {
ctx.Handle(404, "GetCommit", nil) ctx.NotFound("GetCommit", nil)
return return
} }
} else { } else {
ctx.Handle(404, "RepoRef invalid repo", fmt.Errorf("branch or tag not exist: %s", refName)) ctx.NotFound("RepoRef invalid repo", fmt.Errorf("branch or tag not exist: %s", refName))
return return
} }
@ -637,7 +637,7 @@ func RepoRefByType(refType RepoRefType) macaron.Handler {
ctx.Repo.CommitsCount, err = ctx.Repo.GetCommitsCount() ctx.Repo.CommitsCount, err = ctx.Repo.GetCommitsCount()
if err != nil { if err != nil {
ctx.Handle(500, "GetCommitsCount", err) ctx.ServerError("GetCommitsCount", err)
return return
} }
ctx.Data["CommitsCount"] = ctx.Repo.CommitsCount ctx.Data["CommitsCount"] = ctx.Repo.CommitsCount
@ -648,7 +648,7 @@ func RepoRefByType(refType RepoRefType) macaron.Handler {
func RequireRepoAdmin() macaron.Handler { func RequireRepoAdmin() macaron.Handler {
return func(ctx *Context) { return func(ctx *Context) {
if !ctx.IsSigned || (!ctx.Repo.IsAdmin() && !ctx.User.IsAdmin) { if !ctx.IsSigned || (!ctx.Repo.IsAdmin() && !ctx.User.IsAdmin) {
ctx.Handle(404, ctx.Req.RequestURI, nil) ctx.NotFound(ctx.Req.RequestURI, nil)
return return
} }
} }
@ -658,7 +658,7 @@ func RequireRepoAdmin() macaron.Handler {
func RequireRepoWriter() macaron.Handler { func RequireRepoWriter() macaron.Handler {
return func(ctx *Context) { return func(ctx *Context) {
if !ctx.IsSigned || (!ctx.Repo.IsWriter() && !ctx.User.IsAdmin) { if !ctx.IsSigned || (!ctx.Repo.IsWriter() && !ctx.User.IsAdmin) {
ctx.Handle(404, ctx.Req.RequestURI, nil) ctx.NotFound(ctx.Req.RequestURI, nil)
return return
} }
} }
@ -678,7 +678,7 @@ func LoadRepoUnits() macaron.Handler {
} }
err := ctx.Repo.Repository.LoadUnitsByUserID(userID, isAdmin) err := ctx.Repo.Repository.LoadUnitsByUserID(userID, isAdmin)
if err != nil { if err != nil {
ctx.Handle(500, "LoadUnitsByUserID", err) ctx.ServerError("LoadUnitsByUserID", err)
return return
} }
} }
@ -688,7 +688,7 @@ func LoadRepoUnits() macaron.Handler {
func CheckUnit(unitType models.UnitType) macaron.Handler { func CheckUnit(unitType models.UnitType) macaron.Handler {
return func(ctx *Context) { return func(ctx *Context) {
if !ctx.Repo.Repository.UnitEnabled(unitType) { if !ctx.Repo.Repository.UnitEnabled(unitType) {
ctx.Handle(404, "CheckUnit", fmt.Errorf("%s: %v", ctx.Tr("units.error.unit_not_allowed"), unitType)) ctx.NotFound("CheckUnit", fmt.Errorf("%s: %v", ctx.Tr("units.error.unit_not_allowed"), unitType))
} }
} }
} }
@ -697,7 +697,7 @@ func CheckUnit(unitType models.UnitType) macaron.Handler {
func CheckAnyUnit(unitTypes ...models.UnitType) macaron.Handler { func CheckAnyUnit(unitTypes ...models.UnitType) macaron.Handler {
return func(ctx *Context) { return func(ctx *Context) {
if !ctx.Repo.Repository.AnyUnitEnabled(unitTypes...) { if !ctx.Repo.Repository.AnyUnitEnabled(unitTypes...) {
ctx.Handle(404, "CheckAnyUnit", fmt.Errorf("%s: %v", ctx.Tr("units.error.unit_not_allowed"), unitTypes)) ctx.NotFound("CheckAnyUnit", fmt.Errorf("%s: %v", ctx.Tr("units.error.unit_not_allowed"), unitTypes))
} }
} }
} }
@ -706,7 +706,7 @@ func CheckAnyUnit(unitTypes ...models.UnitType) macaron.Handler {
func GitHookService() macaron.Handler { func GitHookService() macaron.Handler {
return func(ctx *Context) { return func(ctx *Context) {
if !ctx.User.CanEditGitHook() { if !ctx.User.CanEditGitHook() {
ctx.Handle(404, "GitHookService", nil) ctx.NotFound("GitHookService", nil)
return return
} }
} }

View File

@ -35,7 +35,7 @@ func Authentications(ctx *context.Context) {
var err error var err error
ctx.Data["Sources"], err = models.LoginSources() ctx.Data["Sources"], err = models.LoginSources()
if err != nil { if err != nil {
ctx.Handle(500, "LoginSources", err) ctx.ServerError("LoginSources", err)
return return
} }
@ -197,7 +197,7 @@ func NewAuthSourcePost(ctx *context.Context, form auth.AuthenticationForm) {
ctx.Data["Err_Name"] = true ctx.Data["Err_Name"] = true
ctx.RenderWithErr(ctx.Tr("admin.auths.login_source_exist", err.(models.ErrLoginSourceAlreadyExist).Name), tplAuthNew, form) ctx.RenderWithErr(ctx.Tr("admin.auths.login_source_exist", err.(models.ErrLoginSourceAlreadyExist).Name), tplAuthNew, form)
} else { } else {
ctx.Handle(500, "CreateSource", err) ctx.ServerError("CreateSource", err)
} }
return return
} }
@ -221,7 +221,7 @@ func EditAuthSource(ctx *context.Context) {
source, err := models.GetLoginSourceByID(ctx.ParamsInt64(":authid")) source, err := models.GetLoginSourceByID(ctx.ParamsInt64(":authid"))
if err != nil { if err != nil {
ctx.Handle(500, "GetLoginSourceByID", err) ctx.ServerError("GetLoginSourceByID", err)
return return
} }
ctx.Data["Source"] = source ctx.Data["Source"] = source
@ -245,7 +245,7 @@ func EditAuthSourcePost(ctx *context.Context, form auth.AuthenticationForm) {
source, err := models.GetLoginSourceByID(ctx.ParamsInt64(":authid")) source, err := models.GetLoginSourceByID(ctx.ParamsInt64(":authid"))
if err != nil { if err != nil {
ctx.Handle(500, "GetLoginSourceByID", err) ctx.ServerError("GetLoginSourceByID", err)
return return
} }
ctx.Data["Source"] = source ctx.Data["Source"] = source
@ -282,7 +282,7 @@ func EditAuthSourcePost(ctx *context.Context, form auth.AuthenticationForm) {
ctx.Flash.Error(err.Error(), true) ctx.Flash.Error(err.Error(), true)
ctx.HTML(200, tplAuthEdit) ctx.HTML(200, tplAuthEdit)
} else { } else {
ctx.Handle(500, "UpdateSource", err) ctx.ServerError("UpdateSource", err)
} }
return return
} }
@ -296,7 +296,7 @@ func EditAuthSourcePost(ctx *context.Context, form auth.AuthenticationForm) {
func DeleteAuthSource(ctx *context.Context) { func DeleteAuthSource(ctx *context.Context) {
source, err := models.GetLoginSourceByID(ctx.ParamsInt64(":authid")) source, err := models.GetLoginSourceByID(ctx.ParamsInt64(":authid"))
if err != nil { if err != nil {
ctx.Handle(500, "GetLoginSourceByID", err) ctx.ServerError("GetLoginSourceByID", err)
return return
} }

View File

@ -34,7 +34,7 @@ func Notices(ctx *context.Context) {
notices, err := models.Notices(page, setting.UI.Admin.NoticePagingNum) notices, err := models.Notices(page, setting.UI.Admin.NoticePagingNum)
if err != nil { if err != nil {
ctx.Handle(500, "Notices", err) ctx.ServerError("Notices", err)
return return
} }
ctx.Data["Notices"] = notices ctx.Data["Notices"] = notices
@ -66,7 +66,7 @@ func DeleteNotices(ctx *context.Context) {
// EmptyNotices delete all the notices // EmptyNotices delete all the notices
func EmptyNotices(ctx *context.Context) { func EmptyNotices(ctx *context.Context) {
if err := models.DeleteNotices(0, 0); err != nil { if err := models.DeleteNotices(0, 0); err != nil {
ctx.Handle(500, "DeleteNotices", err) ctx.ServerError("DeleteNotices", err)
return return
} }

View File

@ -34,12 +34,12 @@ func Repos(ctx *context.Context) {
func DeleteRepo(ctx *context.Context) { func DeleteRepo(ctx *context.Context) {
repo, err := models.GetRepositoryByID(ctx.QueryInt64("id")) repo, err := models.GetRepositoryByID(ctx.QueryInt64("id"))
if err != nil { if err != nil {
ctx.Handle(500, "GetRepositoryByID", err) ctx.ServerError("GetRepositoryByID", err)
return return
} }
if err := models.DeleteRepository(ctx.User, repo.MustOwner().ID, repo.ID); err != nil { if err := models.DeleteRepository(ctx.User, repo.MustOwner().ID, repo.ID); err != nil {
ctx.Handle(500, "DeleteRepository", err) ctx.ServerError("DeleteRepository", err)
return return
} }
log.Trace("Repository deleted: %s/%s", repo.MustOwner().Name, repo.Name) log.Trace("Repository deleted: %s/%s", repo.MustOwner().Name, repo.Name)

View File

@ -47,7 +47,7 @@ func NewUser(ctx *context.Context) {
sources, err := models.LoginSources() sources, err := models.LoginSources()
if err != nil { if err != nil {
ctx.Handle(500, "LoginSources", err) ctx.ServerError("LoginSources", err)
return return
} }
ctx.Data["Sources"] = sources ctx.Data["Sources"] = sources
@ -64,7 +64,7 @@ func NewUserPost(ctx *context.Context, form auth.AdminCreateUserForm) {
sources, err := models.LoginSources() sources, err := models.LoginSources()
if err != nil { if err != nil {
ctx.Handle(500, "LoginSources", err) ctx.ServerError("LoginSources", err)
return return
} }
ctx.Data["Sources"] = sources ctx.Data["Sources"] = sources
@ -108,7 +108,7 @@ func NewUserPost(ctx *context.Context, form auth.AdminCreateUserForm) {
ctx.Data["Err_UserName"] = true ctx.Data["Err_UserName"] = true
ctx.RenderWithErr(ctx.Tr("user.form.name_pattern_not_allowed", err.(models.ErrNamePatternNotAllowed).Pattern), tplUserNew, &form) ctx.RenderWithErr(ctx.Tr("user.form.name_pattern_not_allowed", err.(models.ErrNamePatternNotAllowed).Pattern), tplUserNew, &form)
default: default:
ctx.Handle(500, "CreateUser", err) ctx.ServerError("CreateUser", err)
} }
return return
} }
@ -126,7 +126,7 @@ func NewUserPost(ctx *context.Context, form auth.AdminCreateUserForm) {
func prepareUserInfo(ctx *context.Context) *models.User { func prepareUserInfo(ctx *context.Context) *models.User {
u, err := models.GetUserByID(ctx.ParamsInt64(":userid")) u, err := models.GetUserByID(ctx.ParamsInt64(":userid"))
if err != nil { if err != nil {
ctx.Handle(500, "GetUserByID", err) ctx.ServerError("GetUserByID", err)
return nil return nil
} }
ctx.Data["User"] = u ctx.Data["User"] = u
@ -134,7 +134,7 @@ func prepareUserInfo(ctx *context.Context) *models.User {
if u.LoginSource > 0 { if u.LoginSource > 0 {
ctx.Data["LoginSource"], err = models.GetLoginSourceByID(u.LoginSource) ctx.Data["LoginSource"], err = models.GetLoginSourceByID(u.LoginSource)
if err != nil { if err != nil {
ctx.Handle(500, "GetLoginSourceByID", err) ctx.ServerError("GetLoginSourceByID", err)
return nil return nil
} }
} else { } else {
@ -143,7 +143,7 @@ func prepareUserInfo(ctx *context.Context) *models.User {
sources, err := models.LoginSources() sources, err := models.LoginSources()
if err != nil { if err != nil {
ctx.Handle(500, "LoginSources", err) ctx.ServerError("LoginSources", err)
return nil return nil
} }
ctx.Data["Sources"] = sources ctx.Data["Sources"] = sources
@ -197,7 +197,7 @@ func EditUserPost(ctx *context.Context, form auth.AdminEditUserForm) {
u.Passwd = form.Password u.Passwd = form.Password
var err error var err error
if u.Salt, err = models.GetUserSalt(); err != nil { if u.Salt, err = models.GetUserSalt(); err != nil {
ctx.Handle(500, "UpdateUser", err) ctx.ServerError("UpdateUser", err)
return return
} }
u.HashPassword() u.HashPassword()
@ -221,7 +221,7 @@ func EditUserPost(ctx *context.Context, form auth.AdminEditUserForm) {
ctx.Data["Err_Email"] = true ctx.Data["Err_Email"] = true
ctx.RenderWithErr(ctx.Tr("form.email_been_used"), tplUserEdit, &form) ctx.RenderWithErr(ctx.Tr("form.email_been_used"), tplUserEdit, &form)
} else { } else {
ctx.Handle(500, "UpdateUser", err) ctx.ServerError("UpdateUser", err)
} }
return return
} }
@ -235,7 +235,7 @@ func EditUserPost(ctx *context.Context, form auth.AdminEditUserForm) {
func DeleteUser(ctx *context.Context) { func DeleteUser(ctx *context.Context) {
u, err := models.GetUserByID(ctx.ParamsInt64(":userid")) u, err := models.GetUserByID(ctx.ParamsInt64(":userid"))
if err != nil { if err != nil {
ctx.Handle(500, "GetUserByID", err) ctx.ServerError("GetUserByID", err)
return return
} }
@ -252,7 +252,7 @@ func DeleteUser(ctx *context.Context) {
"redirect": setting.AppSubURL + "/admin/users/" + ctx.Params(":userid"), "redirect": setting.AppSubURL + "/admin/users/" + ctx.Params(":userid"),
}) })
default: default:
ctx.Handle(500, "DeleteUser", err) ctx.ServerError("DeleteUser", err)
} }
return return
} }

View File

@ -91,7 +91,7 @@ func CreateFork(ctx *context.APIContext, form api.CreateForkOption) {
} }
isMember, err := org.IsOrgMember(ctx.User.ID) isMember, err := org.IsOrgMember(ctx.User.ID)
if err != nil { if err != nil {
ctx.Handle(500, "IsOrgMember", err) ctx.ServerError("IsOrgMember", err)
return return
} else if !isMember { } else if !isMember {
ctx.Status(403) ctx.Status(403)

View File

@ -193,7 +193,7 @@ func EditLabel(ctx *context.APIContext, form api.EditLabelOption) {
label.Color = *form.Color label.Color = *form.Color
} }
if err := models.UpdateLabel(label); err != nil { if err := models.UpdateLabel(label); err != nil {
ctx.Handle(500, "UpdateLabel", err) ctx.ServerError("UpdateLabel", err)
return return
} }
ctx.JSON(200, label.APIFormat()) ctx.JSON(200, label.APIFormat())

View File

@ -180,7 +180,7 @@ func EditMilestone(ctx *context.APIContext, form api.EditMilestoneOption) {
} }
if err := models.UpdateMilestone(milestone); err != nil { if err := models.UpdateMilestone(milestone); err != nil {
ctx.Handle(500, "UpdateMilestone", err) ctx.ServerError("UpdateMilestone", err)
return return
} }
ctx.JSON(200, milestone.APIFormat()) ctx.JSON(200, milestone.APIFormat())

View File

@ -465,7 +465,7 @@ func MergePullRequest(ctx *context.APIContext, form auth.MergePullRequestForm) {
pr, err := models.GetPullRequestByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index")) pr, err := models.GetPullRequestByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
if err != nil { if err != nil {
if models.IsErrPullRequestNotExist(err) { if models.IsErrPullRequestNotExist(err) {
ctx.Handle(404, "GetPullRequestByIndex", err) ctx.NotFound("GetPullRequestByIndex", err)
} else { } else {
ctx.Error(500, "GetPullRequestByIndex", err) ctx.Error(500, "GetPullRequestByIndex", err)
} }
@ -473,7 +473,7 @@ func MergePullRequest(ctx *context.APIContext, form auth.MergePullRequestForm) {
} }
if err = pr.GetHeadRepo(); err != nil { if err = pr.GetHeadRepo(); err != nil {
ctx.Handle(500, "GetHeadRepo", err) ctx.ServerError("GetHeadRepo", err)
return return
} }
@ -560,9 +560,9 @@ func parseCompareInfo(ctx *context.APIContext, form api.CreatePullRequestOption)
headUser, err = models.GetUserByName(headInfos[0]) headUser, err = models.GetUserByName(headInfos[0])
if err != nil { if err != nil {
if models.IsErrUserNotExist(err) { if models.IsErrUserNotExist(err) {
ctx.Handle(404, "GetUserByName", nil) ctx.NotFound("GetUserByName", nil)
} else { } else {
ctx.Handle(500, "GetUserByName", err) ctx.ServerError("GetUserByName", err)
} }
return nil, nil, nil, nil, "", "" return nil, nil, nil, nil, "", ""
} }

View File

@ -132,7 +132,7 @@ func CreateRelease(ctx *context.APIContext, form api.CreateReleaseOption) {
rel, err := models.GetRelease(ctx.Repo.Repository.ID, form.TagName) rel, err := models.GetRelease(ctx.Repo.Repository.ID, form.TagName)
if err != nil { if err != nil {
if !models.IsErrReleaseNotExist(err) { if !models.IsErrReleaseNotExist(err) {
ctx.Handle(500, "GetRelease", err) ctx.ServerError("GetRelease", err)
return return
} }
rel = &models.Release{ rel = &models.Release{
@ -169,7 +169,7 @@ func CreateRelease(ctx *context.APIContext, form api.CreateReleaseOption) {
rel.IsTag = false rel.IsTag = false
if err = models.UpdateRelease(ctx.Repo.GitRepo, rel, nil); err != nil { if err = models.UpdateRelease(ctx.Repo.GitRepo, rel, nil); err != nil {
ctx.Handle(500, "UpdateRelease", err) ctx.ServerError("UpdateRelease", err)
return return
} }
} }

View File

@ -258,7 +258,7 @@ func CreateOrgRepo(ctx *context.APIContext, opt api.CreateRepoOption) {
isOwner, err := org.IsOwnedBy(ctx.User.ID) isOwner, err := org.IsOwnedBy(ctx.User.ID)
if err != nil { if err != nil {
ctx.Handle(500, "IsOwnedBy", err) ctx.ServerError("IsOwnedBy", err)
return return
} else if !isOwner { } else if !isOwner {
ctx.Error(403, "", "Given user is not owner of organization.") ctx.Error(403, "", "Given user is not owner of organization.")

View File

@ -117,7 +117,7 @@ func RenderRepoSearch(ctx *context.Context, opts *RepoSearchOptions) {
AllPublic: true, AllPublic: true,
}) })
if err != nil { if err != nil {
ctx.Handle(500, "SearchRepositoryByName", err) ctx.ServerError("SearchRepositoryByName", err)
return return
} }
ctx.Data["Keyword"] = keyword 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) { if len(opts.Keyword) == 0 || isKeywordValid(opts.Keyword) {
users, count, err = models.SearchUsers(opts) users, count, err = models.SearchUsers(opts)
if err != nil { if err != nil {
ctx.Handle(500, "SearchUsers", err) ctx.ServerError("SearchUsers", err)
return return
} }
} }
@ -226,5 +226,5 @@ func ExploreOrganizations(ctx *context.Context) {
// NotFound render 404 page // NotFound render 404 page
func NotFound(ctx *context.Context) { func NotFound(ctx *context.Context) {
ctx.Data["Title"] = "Page Not Found" ctx.Data["Title"] = "Page Not Found"
ctx.Handle(404, "home.NotFound", nil) ctx.NotFound("home.NotFound", nil)
} }

View File

@ -33,7 +33,7 @@ const (
// InstallInit prepare for rendering installation page // InstallInit prepare for rendering installation page
func InstallInit(ctx *context.Context) { func InstallInit(ctx *context.Context) {
if setting.InstallLock { if setting.InstallLock {
ctx.Handle(404, "Install", errors.New("Installation is prohibited")) ctx.NotFound("Install", errors.New("Installation is prohibited"))
return return
} }

View File

@ -26,7 +26,7 @@ func Members(ctx *context.Context) {
ctx.Data["PageIsOrgMembers"] = true ctx.Data["PageIsOrgMembers"] = true
if err := org.GetMembers(); err != nil { if err := org.GetMembers(); err != nil {
ctx.Handle(500, "GetMembers", err) ctx.ServerError("GetMembers", err)
return return
} }
ctx.Data["Members"] = org.Members ctx.Data["Members"] = org.Members

View File

@ -22,9 +22,13 @@ const (
// Create render the page for create organization // Create render the page for create organization
func Create(ctx *context.Context) { func Create(ctx *context.Context) {
if !ctx.User.CanCreateOrganization() {
ctx.NotFound("CanCreateOrganization", nil)
}
ctx.Data["Title"] = ctx.Tr("new_org") ctx.Data["Title"] = ctx.Tr("new_org")
if !ctx.User.CanCreateOrganization() { 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 return
} }
ctx.HTML(200, tplCreateOrg) ctx.HTML(200, tplCreateOrg)
@ -32,6 +36,10 @@ func Create(ctx *context.Context) {
// CreatePost response for create organization // CreatePost response for create organization
func CreatePost(ctx *context.Context, form auth.CreateOrgForm) { func CreatePost(ctx *context.Context, form auth.CreateOrgForm) {
if !ctx.User.CanCreateOrganization() {
ctx.NotFound("CanCreateOrganization", nil)
}
ctx.Data["Title"] = ctx.Tr("new_org") ctx.Data["Title"] = ctx.Tr("new_org")
if ctx.HasError() { if ctx.HasError() {
@ -57,7 +65,7 @@ func CreatePost(ctx *context.Context, form auth.CreateOrgForm) {
case models.IsErrUserNotAllowedCreateOrg(err): case models.IsErrUserNotAllowedCreateOrg(err):
ctx.RenderWithErr(ctx.Tr("org.form.create_org_not_allowed"), tplCreateOrg, &form) ctx.RenderWithErr(ctx.Tr("org.form.create_org_not_allowed"), tplCreateOrg, &form)
default: default:
ctx.Handle(500, "CreateOrganization", err) ctx.ServerError("CreateOrganization", err)
} }
return return
} }

View File

@ -48,7 +48,7 @@ func SettingsPost(ctx *context.Context, form auth.UpdateOrgSettingForm) {
if org.LowerName != strings.ToLower(form.Name) { if org.LowerName != strings.ToLower(form.Name) {
isExist, err := models.IsUserExist(org.ID, form.Name) isExist, err := models.IsUserExist(org.ID, form.Name)
if err != nil { if err != nil {
ctx.Handle(500, "IsUserExist", err) ctx.ServerError("IsUserExist", err)
return return
} else if isExist { } else if isExist {
ctx.Data["OrgName"] = true ctx.Data["OrgName"] = true
@ -59,7 +59,7 @@ func SettingsPost(ctx *context.Context, form auth.UpdateOrgSettingForm) {
ctx.Data["OrgName"] = true ctx.Data["OrgName"] = true
ctx.RenderWithErr(ctx.Tr("form.illegal_username"), tplSettingsOptions, &form) ctx.RenderWithErr(ctx.Tr("form.illegal_username"), tplSettingsOptions, &form)
} else { } else {
ctx.Handle(500, "ChangeUserName", err) ctx.ServerError("ChangeUserName", err)
} }
return return
} }
@ -80,7 +80,7 @@ func SettingsPost(ctx *context.Context, form auth.UpdateOrgSettingForm) {
org.Website = form.Website org.Website = form.Website
org.Location = form.Location org.Location = form.Location
if err := models.UpdateUser(org); err != nil { if err := models.UpdateUser(org); err != nil {
ctx.Handle(500, "UpdateUser", err) ctx.ServerError("UpdateUser", err)
return return
} }
log.Trace("Organization setting updated: %s", org.Name) log.Trace("Organization setting updated: %s", org.Name)
@ -120,7 +120,7 @@ func SettingsDelete(ctx *context.Context) {
if models.IsErrUserNotExist(err) { if models.IsErrUserNotExist(err) {
ctx.RenderWithErr(ctx.Tr("form.enterred_invalid_password"), tplSettingsDelete, nil) ctx.RenderWithErr(ctx.Tr("form.enterred_invalid_password"), tplSettingsDelete, nil)
} else { } else {
ctx.Handle(500, "UserSignIn", err) ctx.ServerError("UserSignIn", err)
} }
return return
} }
@ -130,7 +130,7 @@ func SettingsDelete(ctx *context.Context) {
ctx.Flash.Error(ctx.Tr("form.org_still_own_repo")) ctx.Flash.Error(ctx.Tr("form.org_still_own_repo"))
ctx.Redirect(ctx.Org.OrgLink + "/settings/delete") ctx.Redirect(ctx.Org.OrgLink + "/settings/delete")
} else { } else {
ctx.Handle(500, "DeleteOrganization", err) ctx.ServerError("DeleteOrganization", err)
} }
} else { } else {
log.Trace("Organization deleted: %s", org.Name) log.Trace("Organization deleted: %s", org.Name)
@ -151,7 +151,7 @@ func Webhooks(ctx *context.Context) {
ws, err := models.GetWebhooksByOrgID(ctx.Org.Organization.ID) ws, err := models.GetWebhooksByOrgID(ctx.Org.Organization.ID)
if err != nil { if err != nil {
ctx.Handle(500, "GetWebhooksByOrgId", err) ctx.ServerError("GetWebhooksByOrgId", err)
return return
} }

View File

@ -37,7 +37,7 @@ func Teams(ctx *context.Context) {
for _, t := range org.Teams { for _, t := range org.Teams {
if err := t.GetMembers(); err != nil { if err := t.GetMembers(); err != nil {
ctx.Handle(500, "GetMembers", err) ctx.ServerError("GetMembers", err)
return return
} }
} }
@ -85,7 +85,7 @@ func TeamsAction(ctx *context.Context) {
ctx.Flash.Error(ctx.Tr("form.user_not_exist")) ctx.Flash.Error(ctx.Tr("form.user_not_exist"))
ctx.Redirect(ctx.Org.OrgLink + "/teams/" + ctx.Org.Team.LowerName) ctx.Redirect(ctx.Org.OrgLink + "/teams/" + ctx.Org.Team.LowerName)
} else { } else {
ctx.Handle(500, " GetUserByName", err) ctx.ServerError(" GetUserByName", err)
} }
return return
} }
@ -142,7 +142,7 @@ func TeamsRepoAction(ctx *context.Context) {
ctx.Redirect(ctx.Org.OrgLink + "/teams/" + ctx.Org.Team.LowerName + "/repositories") ctx.Redirect(ctx.Org.OrgLink + "/teams/" + ctx.Org.Team.LowerName + "/repositories")
return return
} }
ctx.Handle(500, "GetRepositoryByName", err) ctx.ServerError("GetRepositoryByName", err)
return return
} }
err = ctx.Org.Team.AddRepository(repo) err = ctx.Org.Team.AddRepository(repo)
@ -152,7 +152,7 @@ func TeamsRepoAction(ctx *context.Context) {
if err != nil { if err != nil {
log.Error(3, "Action(%s): '%s' %v", ctx.Params(":action"), ctx.Org.Team.Name, err) 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 return
} }
ctx.Redirect(ctx.Org.OrgLink + "/teams/" + ctx.Org.Team.LowerName + "/repositories") 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): case models.IsErrTeamAlreadyExist(err):
ctx.RenderWithErr(ctx.Tr("form.team_name_been_taken"), tplTeamNew, &form) ctx.RenderWithErr(ctx.Tr("form.team_name_been_taken"), tplTeamNew, &form)
default: default:
ctx.Handle(500, "NewTeam", err) ctx.ServerError("NewTeam", err)
} }
return return
} }
@ -216,7 +216,7 @@ func TeamMembers(ctx *context.Context) {
ctx.Data["Title"] = ctx.Org.Team.Name ctx.Data["Title"] = ctx.Org.Team.Name
ctx.Data["PageIsOrgTeams"] = true ctx.Data["PageIsOrgTeams"] = true
if err := ctx.Org.Team.GetMembers(); err != nil { if err := ctx.Org.Team.GetMembers(); err != nil {
ctx.Handle(500, "GetMembers", err) ctx.ServerError("GetMembers", err)
return return
} }
ctx.HTML(200, tplTeamMembers) ctx.HTML(200, tplTeamMembers)
@ -227,7 +227,7 @@ func TeamRepositories(ctx *context.Context) {
ctx.Data["Title"] = ctx.Org.Team.Name ctx.Data["Title"] = ctx.Org.Team.Name
ctx.Data["PageIsOrgTeams"] = true ctx.Data["PageIsOrgTeams"] = true
if err := ctx.Org.Team.GetRepositories(); err != nil { if err := ctx.Org.Team.GetRepositories(); err != nil {
ctx.Handle(500, "GetRepositories", err) ctx.ServerError("GetRepositories", err)
return return
} }
ctx.HTML(200, tplTeamRepositories) ctx.HTML(200, tplTeamRepositories)
@ -285,7 +285,7 @@ func EditTeamPost(ctx *context.Context, form auth.CreateTeamForm) {
case models.IsErrTeamAlreadyExist(err): case models.IsErrTeamAlreadyExist(err):
ctx.RenderWithErr(ctx.Tr("form.team_name_been_taken"), tplTeamNew, &form) ctx.RenderWithErr(ctx.Tr("form.team_name_been_taken"), tplTeamNew, &form)
default: default:
ctx.Handle(500, "UpdateTeam", err) ctx.ServerError("UpdateTeam", err)
} }
return return
} }

View File

@ -48,7 +48,7 @@ func Activity(ctx *context.Context) {
ctx.Repo.Repository.UnitEnabled(models.UnitTypeReleases), ctx.Repo.Repository.UnitEnabled(models.UnitTypeReleases),
ctx.Repo.Repository.UnitEnabled(models.UnitTypeIssues), ctx.Repo.Repository.UnitEnabled(models.UnitTypeIssues),
ctx.Repo.Repository.UnitEnabled(models.UnitTypePullRequests)); err != nil { ctx.Repo.Repository.UnitEnabled(models.UnitTypePullRequests)); err != nil {
ctx.Handle(500, "GetActivityStats", err) ctx.ServerError("GetActivityStats", err)
return return
} }

View File

@ -136,7 +136,7 @@ func deleteBranch(ctx *context.Context, branchName string) error {
func loadBranches(ctx *context.Context) []*Branch { func loadBranches(ctx *context.Context) []*Branch {
rawBranches, err := ctx.Repo.Repository.GetBranches() rawBranches, err := ctx.Repo.Repository.GetBranches()
if err != nil { if err != nil {
ctx.Handle(500, "GetBranches", err) ctx.ServerError("GetBranches", err)
return nil return nil
} }
@ -144,13 +144,13 @@ func loadBranches(ctx *context.Context) []*Branch {
for i := range rawBranches { for i := range rawBranches {
commit, err := rawBranches[i].GetCommit() commit, err := rawBranches[i].GetCommit()
if err != nil { if err != nil {
ctx.Handle(500, "GetCommit", err) ctx.ServerError("GetCommit", err)
return nil return nil
} }
isProtected, err := ctx.Repo.Repository.IsProtectedBranch(rawBranches[i].Name, ctx.User) isProtected, err := ctx.Repo.Repository.IsProtectedBranch(rawBranches[i].Name, ctx.User)
if err != nil { if err != nil {
ctx.Handle(500, "IsProtectedBranch", err) ctx.ServerError("IsProtectedBranch", err)
return nil return nil
} }
@ -164,7 +164,7 @@ func loadBranches(ctx *context.Context) []*Branch {
if ctx.Repo.IsWriter() { if ctx.Repo.IsWriter() {
deletedBranches, err := getDeletedBranches(ctx) deletedBranches, err := getDeletedBranches(ctx)
if err != nil { if err != nil {
ctx.Handle(500, "getDeletedBranches", err) ctx.ServerError("getDeletedBranches", err)
return nil return nil
} }
branches = append(branches, deletedBranches...) branches = append(branches, deletedBranches...)
@ -196,7 +196,7 @@ func getDeletedBranches(ctx *context.Context) ([]*Branch, error) {
// CreateBranch creates new branch in repository // CreateBranch creates new branch in repository
func CreateBranch(ctx *context.Context, form auth.NewBranchForm) { func CreateBranch(ctx *context.Context, form auth.NewBranchForm) {
if !ctx.Repo.CanCreateBranch() { if !ctx.Repo.CanCreateBranch() {
ctx.Handle(404, "CreateBranch", nil) ctx.NotFound("CreateBranch", nil)
return return
} }
@ -232,7 +232,7 @@ func CreateBranch(ctx *context.Context, form auth.NewBranchForm) {
return return
} }
ctx.Handle(500, "CreateNewBranch", err) ctx.ServerError("CreateNewBranch", err)
return return
} }

View File

@ -40,14 +40,14 @@ func RefCommits(ctx *context.Context) {
func Commits(ctx *context.Context) { func Commits(ctx *context.Context) {
ctx.Data["PageIsCommits"] = true ctx.Data["PageIsCommits"] = true
if ctx.Repo.Commit == nil { if ctx.Repo.Commit == nil {
ctx.Handle(404, "Commit not found", nil) ctx.NotFound("Commit not found", nil)
return return
} }
ctx.Data["PageIsViewCode"] = true ctx.Data["PageIsViewCode"] = true
commitsCount, err := ctx.Repo.GetCommitsCount() commitsCount, err := ctx.Repo.GetCommitsCount()
if err != nil { if err != nil {
ctx.Handle(500, "GetCommitsCount", err) ctx.ServerError("GetCommitsCount", err)
return return
} }
@ -60,7 +60,7 @@ func Commits(ctx *context.Context) {
// Both `git log branchName` and `git log commitId` work. // Both `git log branchName` and `git log commitId` work.
commits, err := ctx.Repo.Commit.CommitsByRange(page) commits, err := ctx.Repo.Commit.CommitsByRange(page)
if err != nil { if err != nil {
ctx.Handle(500, "CommitsByRange", err) ctx.ServerError("CommitsByRange", err)
return return
} }
commits = models.ValidateCommitsWithEmails(commits) commits = models.ValidateCommitsWithEmails(commits)
@ -82,13 +82,13 @@ func Graph(ctx *context.Context) {
commitsCount, err := ctx.Repo.GetCommitsCount() commitsCount, err := ctx.Repo.GetCommitsCount()
if err != nil { if err != nil {
ctx.Handle(500, "GetCommitsCount", err) ctx.ServerError("GetCommitsCount", err)
return return
} }
graph, err := models.GetCommitGraph(ctx.Repo.GitRepo) graph, err := models.GetCommitGraph(ctx.Repo.GitRepo)
if err != nil { if err != nil {
ctx.Handle(500, "GetCommitGraph", err) ctx.ServerError("GetCommitGraph", err)
return return
} }
@ -116,7 +116,7 @@ func SearchCommits(ctx *context.Context) {
commits, err := ctx.Repo.Commit.SearchCommits(keyword, all) commits, err := ctx.Repo.Commit.SearchCommits(keyword, all)
if err != nil { if err != nil {
ctx.Handle(500, "SearchCommits", err) ctx.ServerError("SearchCommits", err)
return return
} }
commits = models.ValidateCommitsWithEmails(commits) commits = models.ValidateCommitsWithEmails(commits)
@ -148,10 +148,10 @@ func FileHistory(ctx *context.Context) {
branchName := ctx.Repo.BranchName branchName := ctx.Repo.BranchName
commitsCount, err := ctx.Repo.GitRepo.FileCommitsCount(branchName, fileName) commitsCount, err := ctx.Repo.GitRepo.FileCommitsCount(branchName, fileName)
if err != nil { if err != nil {
ctx.Handle(500, "FileCommitsCount", err) ctx.ServerError("FileCommitsCount", err)
return return
} else if commitsCount == 0 { } else if commitsCount == 0 {
ctx.Handle(404, "FileCommitsCount", nil) ctx.NotFound("FileCommitsCount", nil)
return return
} }
@ -163,7 +163,7 @@ func FileHistory(ctx *context.Context) {
commits, err := ctx.Repo.GitRepo.CommitsByFileAndRange(branchName, fileName, page) commits, err := ctx.Repo.GitRepo.CommitsByFileAndRange(branchName, fileName, page)
if err != nil { if err != nil {
ctx.Handle(500, "CommitsByFileAndRange", err) ctx.ServerError("CommitsByFileAndRange", err)
return return
} }
commits = models.ValidateCommitsWithEmails(commits) commits = models.ValidateCommitsWithEmails(commits)
@ -191,9 +191,9 @@ func Diff(ctx *context.Context) {
commit, err := ctx.Repo.GitRepo.GetCommit(commitID) commit, err := ctx.Repo.GitRepo.GetCommit(commitID)
if err != nil { if err != nil {
if git.IsErrNotExist(err) { if git.IsErrNotExist(err) {
ctx.Handle(404, "Repo.GitRepo.GetCommit", err) ctx.NotFound("Repo.GitRepo.GetCommit", err)
} else { } else {
ctx.Handle(500, "Repo.GitRepo.GetCommit", err) ctx.ServerError("Repo.GitRepo.GetCommit", err)
} }
return return
} }
@ -212,7 +212,7 @@ func Diff(ctx *context.Context) {
commitID, setting.Git.MaxGitDiffLines, commitID, setting.Git.MaxGitDiffLines,
setting.Git.MaxGitDiffLineCharacters, setting.Git.MaxGitDiffFiles) setting.Git.MaxGitDiffLineCharacters, setting.Git.MaxGitDiffFiles)
if err != nil { if err != nil {
ctx.Handle(404, "GetDiffCommit", err) ctx.NotFound("GetDiffCommit", err)
return return
} }
@ -221,7 +221,7 @@ func Diff(ctx *context.Context) {
sha, err := commit.ParentID(i) sha, err := commit.ParentID(i)
parents[i] = sha.String() parents[i] = sha.String()
if err != nil { if err != nil {
ctx.Handle(404, "repo.Diff", err) ctx.NotFound("repo.Diff", err)
return return
} }
} }
@ -253,7 +253,7 @@ func RawDiff(ctx *context.Context) {
models.RawDiffType(ctx.Params(":ext")), models.RawDiffType(ctx.Params(":ext")),
ctx.Resp, ctx.Resp,
); err != nil { ); err != nil {
ctx.Handle(500, "GetRawDiff", err) ctx.ServerError("GetRawDiff", err)
return return
} }
} }
@ -269,7 +269,7 @@ func CompareDiff(ctx *context.Context) {
commit, err := ctx.Repo.GitRepo.GetCommit(afterCommitID) commit, err := ctx.Repo.GitRepo.GetCommit(afterCommitID)
if err != nil { if err != nil {
ctx.Handle(404, "GetCommit", err) ctx.NotFound("GetCommit", err)
return return
} }
@ -277,13 +277,13 @@ func CompareDiff(ctx *context.Context) {
afterCommitID, setting.Git.MaxGitDiffLines, afterCommitID, setting.Git.MaxGitDiffLines,
setting.Git.MaxGitDiffLineCharacters, setting.Git.MaxGitDiffFiles) setting.Git.MaxGitDiffLineCharacters, setting.Git.MaxGitDiffFiles)
if err != nil { if err != nil {
ctx.Handle(404, "GetDiffRange", err) ctx.NotFound("GetDiffRange", err)
return return
} }
commits, err := commit.CommitsBeforeUntil(beforeCommitID) commits, err := commit.CommitsBeforeUntil(beforeCommitID)
if err != nil { if err != nil {
ctx.Handle(500, "CommitsBeforeUntil", err) ctx.ServerError("CommitsBeforeUntil", err)
return return
} }
commits = models.ValidateCommitsWithEmails(commits) commits = models.ValidateCommitsWithEmails(commits)

View File

@ -59,13 +59,13 @@ func SingleDownload(ctx *context.Context) {
blob, err := ctx.Repo.Commit.GetBlobByPath(ctx.Repo.TreePath) blob, err := ctx.Repo.Commit.GetBlobByPath(ctx.Repo.TreePath)
if err != nil { if err != nil {
if git.IsErrNotExist(err) { if git.IsErrNotExist(err) {
ctx.Handle(404, "GetBlobByPath", nil) ctx.NotFound("GetBlobByPath", nil)
} else { } else {
ctx.Handle(500, "GetBlobByPath", err) ctx.ServerError("GetBlobByPath", err)
} }
return return
} }
if err = ServeBlob(ctx, blob); err != nil { if err = ServeBlob(ctx, blob); err != nil {
ctx.Handle(500, "ServeBlob", err) ctx.ServerError("ServeBlob", err)
} }
} }

View File

@ -73,19 +73,19 @@ func editFile(ctx *context.Context, isNewFile bool) {
// No way to edit a directory online. // No way to edit a directory online.
if entry.IsDir() { if entry.IsDir() {
ctx.Handle(404, "entry.IsDir", nil) ctx.NotFound("entry.IsDir", nil)
return return
} }
blob := entry.Blob() blob := entry.Blob()
if blob.Size() >= setting.UI.MaxDisplayFileSize { if blob.Size() >= setting.UI.MaxDisplayFileSize {
ctx.Handle(404, "blob.Size", err) ctx.NotFound("blob.Size", err)
return return
} }
dataRc, err := blob.Data() dataRc, err := blob.Data()
if err != nil { if err != nil {
ctx.Handle(404, "blob.Data", err) ctx.NotFound("blob.Data", err)
return return
} }
@ -98,7 +98,7 @@ func editFile(ctx *context.Context, isNewFile bool) {
// Only text file are editable online. // Only text file are editable online.
if !base.IsTextFile(buf) { if !base.IsTextFile(buf) {
ctx.Handle(404, "base.IsTextFile", nil) ctx.NotFound("base.IsTextFile", nil)
return return
} }
@ -214,7 +214,7 @@ func editFilePost(ctx *context.Context, form auth.EditRepoFileForm, isNewFile bo
break break
} }
ctx.Handle(500, "Repo.Commit.GetTreeEntryByPath", err) ctx.ServerError("Repo.Commit.GetTreeEntryByPath", err)
return return
} }
if index != len(treeNames)-1 { 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.Data["Err_TreePath"] = true
ctx.RenderWithErr(ctx.Tr("repo.editor.file_editing_no_longer_exists", oldTreePath), tplEditFile, &form) ctx.RenderWithErr(ctx.Tr("repo.editor.file_editing_no_longer_exists", oldTreePath), tplEditFile, &form)
} else { } else {
ctx.Handle(500, "GetTreeEntryByPath", err) ctx.ServerError("GetTreeEntryByPath", err)
} }
return return
} }
if lastCommit != ctx.Repo.CommitID { if lastCommit != ctx.Repo.CommitID {
files, err := ctx.Repo.Commit.GetFilesChangedSinceCommit(lastCommit) files, err := ctx.Repo.Commit.GetFilesChangedSinceCommit(lastCommit)
if err != nil { if err != nil {
ctx.Handle(500, "GetFilesChangedSinceCommit", err) ctx.ServerError("GetFilesChangedSinceCommit", err)
return return
} }
@ -269,7 +269,7 @@ func editFilePost(ctx *context.Context, form auth.EditRepoFileForm, isNewFile bo
entry, err := ctx.Repo.Commit.GetTreeEntryByPath(form.TreePath) entry, err := ctx.Repo.Commit.GetTreeEntryByPath(form.TreePath)
if err != nil { if err != nil {
if !git.IsErrNotExist(err) { if !git.IsErrNotExist(err) {
ctx.Handle(500, "GetTreeEntryByPath", err) ctx.ServerError("GetTreeEntryByPath", err)
return return
} }
} }
@ -422,7 +422,7 @@ func DeleteFilePost(ctx *context.Context, form auth.DeleteRepoFileForm) {
TreePath: ctx.Repo.TreePath, TreePath: ctx.Repo.TreePath,
Message: message, Message: message,
}); err != nil { }); err != nil {
ctx.Handle(500, "DeleteRepoFile", err) ctx.ServerError("DeleteRepoFile", err)
return return
} }
@ -521,7 +521,7 @@ func UploadFilePost(ctx *context.Context, form auth.UploadRepoFileForm) {
break break
} }
ctx.Handle(500, "Repo.Commit.GetTreeEntryByPath", err) ctx.ServerError("Repo.Commit.GetTreeEntryByPath", err)
return return
} }

View File

@ -120,7 +120,7 @@ func HTTP(ctx *context.Context) {
authUser, err = models.UserSignIn(authUsername, authPasswd) authUser, err = models.UserSignIn(authUsername, authPasswd)
if err != nil { if err != nil {
if !models.IsErrUserNotExist(err) { if !models.IsErrUserNotExist(err) {
ctx.Handle(http.StatusInternalServerError, "UserSignIn error: %v", err) ctx.ServerError("UserSignIn error: %v", err)
return return
} }
} }
@ -140,7 +140,7 @@ func HTTP(ctx *context.Context) {
if models.IsErrUserNotExist(err) { if models.IsErrUserNotExist(err) {
ctx.HandleText(http.StatusUnauthorized, "invalid credentials") ctx.HandleText(http.StatusUnauthorized, "invalid credentials")
} else { } else {
ctx.Handle(http.StatusInternalServerError, "GetUserByName", err) ctx.ServerError("GetUserByName", err)
} }
return return
} }
@ -152,7 +152,7 @@ func HTTP(ctx *context.Context) {
if models.IsErrAccessTokenNotExist(err) || models.IsErrAccessTokenEmpty(err) { if models.IsErrAccessTokenNotExist(err) || models.IsErrAccessTokenEmpty(err) {
ctx.HandleText(http.StatusUnauthorized, "invalid credentials") ctx.HandleText(http.StatusUnauthorized, "invalid credentials")
} else { } else {
ctx.Handle(http.StatusInternalServerError, "GetAccessTokenBySha", err) ctx.ServerError("GetAccessTokenBySha", err)
} }
return return
} }
@ -160,7 +160,7 @@ func HTTP(ctx *context.Context) {
if isUsernameToken { if isUsernameToken {
authUser, err = models.GetUserByID(token.UID) authUser, err = models.GetUserByID(token.UID)
if err != nil { if err != nil {
ctx.Handle(http.StatusInternalServerError, "GetUserByID", err) ctx.ServerError("GetUserByID", err)
return return
} }
} else if authUser.ID != token.UID { } else if authUser.ID != token.UID {
@ -170,7 +170,7 @@ func HTTP(ctx *context.Context) {
token.UpdatedUnix = util.TimeStampNow() token.UpdatedUnix = util.TimeStampNow()
if err = models.UpdateAccessToken(token); err != nil { if err = models.UpdateAccessToken(token); err != nil {
ctx.Handle(http.StatusInternalServerError, "UpdateAccessToken", err) ctx.ServerError("UpdateAccessToken", err)
} }
} else { } else {
_, err = models.GetTwoFactorByUID(authUser.ID) _, 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") 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 return
} else if !models.IsErrTwoFactorNotEnrolled(err) { } else if !models.IsErrTwoFactorNotEnrolled(err) {
ctx.Handle(http.StatusInternalServerError, "IsErrTwoFactorNotEnrolled", err) ctx.ServerError("IsErrTwoFactorNotEnrolled", err)
return return
} }
} }
@ -188,13 +188,13 @@ func HTTP(ctx *context.Context) {
if !isPublicPull { if !isPublicPull {
has, err := models.HasAccess(authUser.ID, repo, accessMode) has, err := models.HasAccess(authUser.ID, repo, accessMode)
if err != nil { if err != nil {
ctx.Handle(http.StatusInternalServerError, "HasAccess", err) ctx.ServerError("HasAccess", err)
return return
} else if !has { } else if !has {
if accessMode == models.AccessModeRead { if accessMode == models.AccessModeRead {
has, err = models.HasAccess(authUser.ID, repo, models.AccessModeWrite) has, err = models.HasAccess(authUser.ID, repo, models.AccessModeWrite)
if err != nil { if err != nil {
ctx.Handle(http.StatusInternalServerError, "HasAccess2", err) ctx.ServerError("HasAccess2", err)
return return
} else if !has { } else if !has {
ctx.HandleText(http.StatusForbidden, "User permission denied") 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]) dir, err := getGitRepoPath(m[1])
if err != nil { if err != nil {
log.GitLogger.Error(4, err.Error()) log.GitLogger.Error(4, err.Error())
ctx.Handle(http.StatusNotFound, "HTTPBackend", err) ctx.NotFound("HTTPBackend", err)
return 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 return
} }
} }

View File

@ -64,7 +64,7 @@ var (
func MustEnableIssues(ctx *context.Context) { func MustEnableIssues(ctx *context.Context) {
if !ctx.Repo.Repository.UnitEnabled(models.UnitTypeIssues) && if !ctx.Repo.Repository.UnitEnabled(models.UnitTypeIssues) &&
!ctx.Repo.Repository.UnitEnabled(models.UnitTypeExternalTracker) { !ctx.Repo.Repository.UnitEnabled(models.UnitTypeExternalTracker) {
ctx.Handle(404, "MustEnableIssues", nil) ctx.NotFound("MustEnableIssues", nil)
return return
} }
@ -78,7 +78,7 @@ func MustEnableIssues(ctx *context.Context) {
// MustAllowPulls check if repository enable pull requests // MustAllowPulls check if repository enable pull requests
func MustAllowPulls(ctx *context.Context) { func MustAllowPulls(ctx *context.Context) {
if !ctx.Repo.Repository.AllowsPulls() { if !ctx.Repo.Repository.AllowsPulls() {
ctx.Handle(404, "MustAllowPulls", nil) ctx.NotFound("MustAllowPulls", nil)
return return
} }
@ -167,7 +167,7 @@ func Issues(ctx *context.Context) {
IssueIDs: issueIDs, IssueIDs: issueIDs,
}) })
if err != nil { if err != nil {
ctx.Handle(500, "GetIssueStats", err) ctx.ServerError("GetIssueStats", err)
return return
} }
} }
@ -204,7 +204,7 @@ func Issues(ctx *context.Context) {
IssueIDs: issueIDs, IssueIDs: issueIDs,
}) })
if err != nil { if err != nil {
ctx.Handle(500, "Issues", err) ctx.ServerError("Issues", err)
return return
} }
} }
@ -215,7 +215,7 @@ func Issues(ctx *context.Context) {
if !ctx.IsSigned { if !ctx.IsSigned {
issues[i].IsRead = true issues[i].IsRead = true
} else if err = issues[i].GetIsRead(ctx.User.ID); err != nil { } else if err = issues[i].GetIsRead(ctx.User.ID); err != nil {
ctx.Handle(500, "GetIsRead", err) ctx.ServerError("GetIsRead", err)
return return
} }
} }
@ -224,14 +224,14 @@ func Issues(ctx *context.Context) {
// Get milestones. // Get milestones.
ctx.Data["Milestones"], err = models.GetMilestonesByRepoID(repo.ID) ctx.Data["Milestones"], err = models.GetMilestonesByRepoID(repo.ID)
if err != nil { if err != nil {
ctx.Handle(500, "GetAllRepoMilestones", err) ctx.ServerError("GetAllRepoMilestones", err)
return return
} }
// Get assignees. // Get assignees.
ctx.Data["Assignees"], err = repo.GetAssignees() ctx.Data["Assignees"], err = repo.GetAssignees()
if err != nil { if err != nil {
ctx.Handle(500, "GetAssignees", err) ctx.ServerError("GetAssignees", err)
return return
} }
@ -261,18 +261,18 @@ func RetrieveRepoMilestonesAndAssignees(ctx *context.Context, repo *models.Repos
var err error var err error
ctx.Data["OpenMilestones"], err = models.GetMilestones(repo.ID, -1, false, "") ctx.Data["OpenMilestones"], err = models.GetMilestones(repo.ID, -1, false, "")
if err != nil { if err != nil {
ctx.Handle(500, "GetMilestones", err) ctx.ServerError("GetMilestones", err)
return return
} }
ctx.Data["ClosedMilestones"], err = models.GetMilestones(repo.ID, -1, true, "") ctx.Data["ClosedMilestones"], err = models.GetMilestones(repo.ID, -1, true, "")
if err != nil { if err != nil {
ctx.Handle(500, "GetMilestones", err) ctx.ServerError("GetMilestones", err)
return return
} }
ctx.Data["Assignees"], err = repo.GetAssignees() ctx.Data["Assignees"], err = repo.GetAssignees()
if err != nil { if err != nil {
ctx.Handle(500, "GetAssignees", err) ctx.ServerError("GetAssignees", err)
return return
} }
} }
@ -285,7 +285,7 @@ func RetrieveRepoMetas(ctx *context.Context, repo *models.Repository) []*models.
labels, err := models.GetLabelsByRepoID(repo.ID, "") labels, err := models.GetLabelsByRepoID(repo.ID, "")
if err != nil { if err != nil {
ctx.Handle(500, "GetLabelsByRepoID", err) ctx.ServerError("GetLabelsByRepoID", err)
return nil return nil
} }
ctx.Data["Labels"] = labels ctx.Data["Labels"] = labels
@ -297,7 +297,7 @@ func RetrieveRepoMetas(ctx *context.Context, repo *models.Repository) []*models.
brs, err := ctx.Repo.GitRepo.GetBranches() brs, err := ctx.Repo.GitRepo.GetBranches()
if err != nil { if err != nil {
ctx.Handle(500, "GetBranches", err) ctx.ServerError("GetBranches", err)
return nil return nil
} }
ctx.Data["Branches"] = brs ctx.Data["Branches"] = brs
@ -406,7 +406,7 @@ func ValidateRepoMetas(ctx *context.Context, form auth.CreateIssueForm) ([]int64
if milestoneID > 0 { if milestoneID > 0 {
ctx.Data["Milestone"], err = repo.GetMilestoneByID(milestoneID) ctx.Data["Milestone"], err = repo.GetMilestoneByID(milestoneID)
if err != nil { if err != nil {
ctx.Handle(500, "GetMilestoneByID", err) ctx.ServerError("GetMilestoneByID", err)
return nil, 0, 0 return nil, 0, 0
} }
ctx.Data["milestone_id"] = milestoneID ctx.Data["milestone_id"] = milestoneID
@ -417,7 +417,7 @@ func ValidateRepoMetas(ctx *context.Context, form auth.CreateIssueForm) ([]int64
if assigneeID > 0 { if assigneeID > 0 {
ctx.Data["Assignee"], err = repo.GetAssigneeByID(assigneeID) ctx.Data["Assignee"], err = repo.GetAssigneeByID(assigneeID)
if err != nil { if err != nil {
ctx.Handle(500, "GetAssigneeByID", err) ctx.ServerError("GetAssigneeByID", err)
return nil, 0, 0 return nil, 0, 0
} }
ctx.Data["assignee_id"] = assigneeID ctx.Data["assignee_id"] = assigneeID
@ -465,7 +465,7 @@ func NewIssuePost(ctx *context.Context, form auth.CreateIssueForm) {
Ref: form.Ref, Ref: form.Ref,
} }
if err := models.NewIssue(repo, issue, labelIDs, attachments); err != nil { if err := models.NewIssue(repo, issue, labelIDs, attachments); err != nil {
ctx.Handle(500, "NewIssue", err) ctx.ServerError("NewIssue", err)
return return
} }
@ -505,9 +505,9 @@ func ViewIssue(ctx *context.Context) {
issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index")) issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
if err != nil { if err != nil {
if models.IsErrIssueNotExist(err) { if models.IsErrIssueNotExist(err) {
ctx.Handle(404, "GetIssueByIndex", err) ctx.NotFound("GetIssueByIndex", err)
} else { } else {
ctx.Handle(500, "GetIssueByIndex", err) ctx.ServerError("GetIssueByIndex", err)
} }
return return
} }
@ -518,7 +518,7 @@ func ViewIssue(ctx *context.Context) {
if ctx.User != nil { if ctx.User != nil {
iw, exists, err = models.GetIssueWatch(ctx.User.ID, issue.ID) iw, exists, err = models.GetIssueWatch(ctx.User.ID, issue.ID)
if err != nil { if err != nil {
ctx.Handle(500, "GetIssueWatch", err) ctx.ServerError("GetIssueWatch", err)
return return
} }
if !exists { if !exists {
@ -581,7 +581,7 @@ func ViewIssue(ctx *context.Context) {
} }
labels, err := models.GetLabelsByRepoID(repo.ID, "") labels, err := models.GetLabelsByRepoID(repo.ID, "")
if err != nil { if err != nil {
ctx.Handle(500, "GetLabelsByRepoID", err) ctx.ServerError("GetLabelsByRepoID", err)
return return
} }
hasSelected := false hasSelected := false
@ -605,7 +605,7 @@ func ViewIssue(ctx *context.Context) {
if ctx.IsSigned { if ctx.IsSigned {
// Update issue-user. // Update issue-user.
if err = issue.ReadBy(ctx.User.ID); err != nil { if err = issue.ReadBy(ctx.User.ID); err != nil {
ctx.Handle(500, "ReadBy", err) ctx.ServerError("ReadBy", err)
return return
} }
} }
@ -625,7 +625,7 @@ func ViewIssue(ctx *context.Context) {
var exists bool var exists bool
var sw *models.Stopwatch var sw *models.Stopwatch
if exists, sw, err = models.HasUserStopwatch(ctx.User.ID); err != nil { if exists, sw, err = models.HasUserStopwatch(ctx.User.ID); err != nil {
ctx.Handle(500, "HasUserStopwatch", err) ctx.ServerError("HasUserStopwatch", err)
return return
} }
ctx.Data["HasUserStopwatch"] = exists ctx.Data["HasUserStopwatch"] = exists
@ -633,7 +633,7 @@ func ViewIssue(ctx *context.Context) {
// Add warning if the user has already a stopwatch // Add warning if the user has already a stopwatch
var otherIssue *models.Issue var otherIssue *models.Issue
if otherIssue, err = models.GetIssueByID(sw.IssueID); err != nil { if otherIssue, err = models.GetIssueByID(sw.IssueID); err != nil {
ctx.Handle(500, "GetIssueByID", err) ctx.ServerError("GetIssueByID", err)
return return
} }
// Add link to the issue of the already running stopwatch // Add link to the issue of the already running stopwatch
@ -645,7 +645,7 @@ func ViewIssue(ctx *context.Context) {
ctx.Data["CanUseTimetracker"] = false ctx.Data["CanUseTimetracker"] = false
} }
if ctx.Data["WorkingUsers"], err = models.TotalTimes(models.FindTrackedTimesOptions{IssueID: issue.ID}); err != nil { if ctx.Data["WorkingUsers"], err = models.TotalTimes(models.FindTrackedTimesOptions{IssueID: issue.ID}); err != nil {
ctx.Handle(500, "TotalTimes", err) ctx.ServerError("TotalTimes", err)
return return
} }
} }
@ -666,7 +666,7 @@ func ViewIssue(ctx *context.Context) {
comment.ShowTag, err = commentTag(repo, comment.Poster, issue) comment.ShowTag, err = commentTag(repo, comment.Poster, issue)
if err != nil { if err != nil {
ctx.Handle(500, "commentTag", err) ctx.ServerError("commentTag", err)
return return
} }
marked[comment.PosterID] = comment.ShowTag marked[comment.PosterID] = comment.ShowTag
@ -683,12 +683,12 @@ func ViewIssue(ctx *context.Context) {
} }
} else if comment.Type == models.CommentTypeLabel { } else if comment.Type == models.CommentTypeLabel {
if err = comment.LoadLabel(); err != nil { if err = comment.LoadLabel(); err != nil {
ctx.Handle(500, "LoadLabel", err) ctx.ServerError("LoadLabel", err)
return return
} }
} else if comment.Type == models.CommentTypeMilestone { } else if comment.Type == models.CommentTypeMilestone {
if err = comment.LoadMilestone(); err != nil { if err = comment.LoadMilestone(); err != nil {
ctx.Handle(500, "LoadMilestone", err) ctx.ServerError("LoadMilestone", err)
return return
} }
ghostMilestone := &models.Milestone{ ghostMilestone := &models.Milestone{
@ -703,7 +703,7 @@ func ViewIssue(ctx *context.Context) {
} }
} else if comment.Type == models.CommentTypeAssignees { } else if comment.Type == models.CommentTypeAssignees {
if err = comment.LoadAssignees(); err != nil { if err = comment.LoadAssignees(); err != nil {
ctx.Handle(500, "LoadAssignees", err) ctx.ServerError("LoadAssignees", err)
return return
} }
} }
@ -729,7 +729,7 @@ func ViewIssue(ctx *context.Context) {
prUnit, err := repo.GetUnit(models.UnitTypePullRequests) prUnit, err := repo.GetUnit(models.UnitTypePullRequests)
if err != nil { if err != nil {
ctx.Handle(500, "GetUnit", err) ctx.ServerError("GetUnit", err)
return return
} }
prConfig := prUnit.PullRequestsConfig() prConfig := prUnit.PullRequestsConfig()
@ -771,7 +771,7 @@ func GetActionIssue(ctx *context.Context) *models.Issue {
return nil return nil
} }
if err = issue.LoadAttributes(); err != nil { if err = issue.LoadAttributes(); err != nil {
ctx.Handle(500, "LoadAttributes", nil) ctx.ServerError("LoadAttributes", nil)
return nil return nil
} }
return issue return issue
@ -780,7 +780,7 @@ func GetActionIssue(ctx *context.Context) *models.Issue {
func checkIssueRights(ctx *context.Context, issue *models.Issue) { func checkIssueRights(ctx *context.Context, issue *models.Issue) {
if issue.IsPull && !ctx.Repo.Repository.UnitEnabled(models.UnitTypePullRequests) || if issue.IsPull && !ctx.Repo.Repository.UnitEnabled(models.UnitTypePullRequests) ||
!issue.IsPull && !ctx.Repo.Repository.UnitEnabled(models.UnitTypeIssues) { !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, ",") { for _, stringIssueID := range strings.Split(commaSeparatedIssueIDs, ",") {
issueID, err := strconv.ParseInt(stringIssueID, 10, 64) issueID, err := strconv.ParseInt(stringIssueID, 10, 64)
if err != nil { if err != nil {
ctx.Handle(500, "ParseInt", err) ctx.ServerError("ParseInt", err)
return nil return nil
} }
issueIDs = append(issueIDs, issueID) issueIDs = append(issueIDs, issueID)
} }
issues, err := models.GetIssuesByIDs(issueIDs) issues, err := models.GetIssuesByIDs(issueIDs)
if err != nil { if err != nil {
ctx.Handle(500, "GetIssuesByIDs", err) ctx.ServerError("GetIssuesByIDs", err)
return nil return nil
} }
// Check access rights for all issues // Check access rights for all issues
@ -808,11 +808,11 @@ func getActionIssues(ctx *context.Context) []*models.Issue {
prUnitEnabled := ctx.Repo.Repository.UnitEnabled(models.UnitTypePullRequests) prUnitEnabled := ctx.Repo.Repository.UnitEnabled(models.UnitTypePullRequests)
for _, issue := range issues { for _, issue := range issues {
if issue.IsPull && !prUnitEnabled || !issue.IsPull && !issueUnitEnabled { if issue.IsPull && !prUnitEnabled || !issue.IsPull && !issueUnitEnabled {
ctx.Handle(404, "IssueOrPullRequestUnitNotAllowed", nil) ctx.NotFound("IssueOrPullRequestUnitNotAllowed", nil)
return nil return nil
} }
if err = issue.LoadAttributes(); err != nil { if err = issue.LoadAttributes(); err != nil {
ctx.Handle(500, "LoadAttributes", err) ctx.ServerError("LoadAttributes", err)
return nil return nil
} }
} }
@ -838,7 +838,7 @@ func UpdateIssueTitle(ctx *context.Context) {
} }
if err := issue.ChangeTitle(ctx.User, title); err != nil { if err := issue.ChangeTitle(ctx.User, title); err != nil {
ctx.Handle(500, "ChangeTitle", err) ctx.ServerError("ChangeTitle", err)
return return
} }
@ -861,7 +861,7 @@ func UpdateIssueContent(ctx *context.Context) {
content := ctx.Query("content") content := ctx.Query("content")
if err := issue.ChangeContent(ctx.User, content); err != nil { if err := issue.ChangeContent(ctx.User, content); err != nil {
ctx.Handle(500, "ChangeContent", err) ctx.ServerError("ChangeContent", err)
return return
} }
@ -885,7 +885,7 @@ func UpdateIssueMilestone(ctx *context.Context) {
} }
issue.MilestoneID = milestoneID issue.MilestoneID = milestoneID
if err := models.ChangeMilestoneAssign(issue, ctx.User, oldMilestoneID); err != nil { if err := models.ChangeMilestoneAssign(issue, ctx.User, oldMilestoneID); err != nil {
ctx.Handle(500, "ChangeMilestoneAssign", err) ctx.ServerError("ChangeMilestoneAssign", err)
return return
} }
} }
@ -908,7 +908,7 @@ func UpdateIssueAssignee(ctx *context.Context) {
continue continue
} }
if err := issue.ChangeAssignee(ctx.User, assigneeID); err != nil { if err := issue.ChangeAssignee(ctx.User, assigneeID); err != nil {
ctx.Handle(500, "ChangeAssignee", err) ctx.ServerError("ChangeAssignee", err)
return return
} }
} }
@ -935,12 +935,12 @@ func UpdateIssueStatus(ctx *context.Context) {
} }
if _, err := models.IssueList(issues).LoadRepositories(); err != nil { if _, err := models.IssueList(issues).LoadRepositories(); err != nil {
ctx.Handle(500, "LoadRepositories", err) ctx.ServerError("LoadRepositories", err)
return return
} }
for _, issue := range issues { for _, issue := range issues {
if err := issue.ChangeStatus(ctx.User, issue.Repo, isClosed); err != nil { if err := issue.ChangeStatus(ctx.User, issue.Repo, isClosed); err != nil {
ctx.Handle(500, "ChangeStatus", err) ctx.ServerError("ChangeStatus", err)
return 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) pr, err := models.GetUnmergedPullRequest(pull.HeadRepoID, pull.BaseRepoID, pull.HeadBranch, pull.BaseBranch)
if err != nil { if err != nil {
if !models.IsErrPullRequestNotExist(err) { if !models.IsErrPullRequestNotExist(err) {
ctx.Handle(500, "GetUnmergedPullRequest", err) ctx.ServerError("GetUnmergedPullRequest", err)
return return
} }
} }
@ -990,7 +990,7 @@ func NewComment(ctx *context.Context, form auth.CreateCommentForm) {
// Regenerate patch and test conflict. // Regenerate patch and test conflict.
if pr == nil { if pr == nil {
if err = issue.PullRequest.UpdatePatch(); err != nil { if err = issue.PullRequest.UpdatePatch(); err != nil {
ctx.Handle(500, "UpdatePatch", err) ctx.ServerError("UpdatePatch", err)
return 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) comment, err := models.CreateIssueComment(ctx.User, ctx.Repo.Repository, issue, form.Content, attachments)
if err != nil { if err != nil {
ctx.Handle(500, "CreateIssueComment", err) ctx.ServerError("CreateIssueComment", err)
return return
} }
@ -1063,7 +1063,7 @@ func UpdateCommentContent(ctx *context.Context) {
return return
} }
if err = models.UpdateComment(comment); err != nil { if err = models.UpdateComment(comment); err != nil {
ctx.Handle(500, "UpdateComment", err) ctx.ServerError("UpdateComment", err)
return return
} }
@ -1089,7 +1089,7 @@ func DeleteComment(ctx *context.Context) {
} }
if err = models.DeleteComment(comment); err != nil { if err = models.DeleteComment(comment); err != nil {
ctx.Handle(500, "DeleteCommentByID", err) ctx.ServerError("DeleteCommentByID", err)
return return
} }
@ -1105,7 +1105,7 @@ func Milestones(ctx *context.Context) {
isShowClosed := ctx.Query("state") == "closed" isShowClosed := ctx.Query("state") == "closed"
openCount, closedCount, err := models.MilestoneStats(ctx.Repo.Repository.ID) openCount, closedCount, err := models.MilestoneStats(ctx.Repo.Repository.ID)
if err != nil { if err != nil {
ctx.Handle(500, "MilestoneStats", err) ctx.ServerError("MilestoneStats", err)
return return
} }
ctx.Data["OpenCount"] = openCount ctx.Data["OpenCount"] = openCount
@ -1127,7 +1127,7 @@ func Milestones(ctx *context.Context) {
miles, err := models.GetMilestones(ctx.Repo.Repository.ID, page, isShowClosed, sortType) miles, err := models.GetMilestones(ctx.Repo.Repository.ID, page, isShowClosed, sortType)
if err != nil { if err != nil {
ctx.Handle(500, "GetMilestones", err) ctx.ServerError("GetMilestones", err)
return return
} }
for _, m := range miles { for _, m := range miles {
@ -1185,7 +1185,7 @@ func NewMilestonePost(ctx *context.Context, form auth.CreateMilestoneForm) {
Content: form.Content, Content: form.Content,
DeadlineUnix: util.TimeStamp(deadline.Unix()), DeadlineUnix: util.TimeStamp(deadline.Unix()),
}); err != nil { }); err != nil {
ctx.Handle(500, "NewMilestone", err) ctx.ServerError("NewMilestone", err)
return return
} }
@ -1204,9 +1204,9 @@ func EditMilestone(ctx *context.Context) {
m, err := models.GetMilestoneByRepoID(ctx.Repo.Repository.ID, ctx.ParamsInt64(":id")) m, err := models.GetMilestoneByRepoID(ctx.Repo.Repository.ID, ctx.ParamsInt64(":id"))
if err != nil { if err != nil {
if models.IsErrMilestoneNotExist(err) { if models.IsErrMilestoneNotExist(err) {
ctx.Handle(404, "", nil) ctx.NotFound("", nil)
} else { } else {
ctx.Handle(500, "GetMilestoneByRepoID", err) ctx.ServerError("GetMilestoneByRepoID", err)
} }
return return
} }
@ -1244,9 +1244,9 @@ func EditMilestonePost(ctx *context.Context, form auth.CreateMilestoneForm) {
m, err := models.GetMilestoneByRepoID(ctx.Repo.Repository.ID, ctx.ParamsInt64(":id")) m, err := models.GetMilestoneByRepoID(ctx.Repo.Repository.ID, ctx.ParamsInt64(":id"))
if err != nil { if err != nil {
if models.IsErrMilestoneNotExist(err) { if models.IsErrMilestoneNotExist(err) {
ctx.Handle(404, "", nil) ctx.NotFound("", nil)
} else { } else {
ctx.Handle(500, "GetMilestoneByRepoID", err) ctx.ServerError("GetMilestoneByRepoID", err)
} }
return return
} }
@ -1254,7 +1254,7 @@ func EditMilestonePost(ctx *context.Context, form auth.CreateMilestoneForm) {
m.Content = form.Content m.Content = form.Content
m.DeadlineUnix = util.TimeStamp(deadline.Unix()) m.DeadlineUnix = util.TimeStamp(deadline.Unix())
if err = models.UpdateMilestone(m); err != nil { if err = models.UpdateMilestone(m); err != nil {
ctx.Handle(500, "UpdateMilestone", err) ctx.ServerError("UpdateMilestone", err)
return return
} }
@ -1267,9 +1267,9 @@ func ChangeMilestonStatus(ctx *context.Context) {
m, err := models.GetMilestoneByRepoID(ctx.Repo.Repository.ID, ctx.ParamsInt64(":id")) m, err := models.GetMilestoneByRepoID(ctx.Repo.Repository.ID, ctx.ParamsInt64(":id"))
if err != nil { if err != nil {
if models.IsErrMilestoneNotExist(err) { if models.IsErrMilestoneNotExist(err) {
ctx.Handle(404, "", err) ctx.NotFound("", err)
} else { } else {
ctx.Handle(500, "GetMilestoneByRepoID", err) ctx.ServerError("GetMilestoneByRepoID", err)
} }
return return
} }
@ -1278,7 +1278,7 @@ func ChangeMilestonStatus(ctx *context.Context) {
case "open": case "open":
if m.IsClosed { if m.IsClosed {
if err = models.ChangeMilestoneStatus(m, false); err != nil { if err = models.ChangeMilestoneStatus(m, false); err != nil {
ctx.Handle(500, "ChangeMilestoneStatus", err) ctx.ServerError("ChangeMilestoneStatus", err)
return return
} }
} }
@ -1287,7 +1287,7 @@ func ChangeMilestonStatus(ctx *context.Context) {
if !m.IsClosed { if !m.IsClosed {
m.ClosedDateUnix = util.TimeStampNow() m.ClosedDateUnix = util.TimeStampNow()
if err = models.ChangeMilestoneStatus(m, true); err != nil { if err = models.ChangeMilestoneStatus(m, true); err != nil {
ctx.Handle(500, "ChangeMilestoneStatus", err) ctx.ServerError("ChangeMilestoneStatus", err)
return return
} }
} }
@ -1318,7 +1318,7 @@ func ChangeIssueReaction(ctx *context.Context, form auth.ReactionForm) {
} }
if ctx.HasError() { if ctx.HasError() {
ctx.Handle(500, "ChangeIssueReaction", errors.New(ctx.GetErrMsg())) ctx.ServerError("ChangeIssueReaction", errors.New(ctx.GetErrMsg()))
return 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) log.Trace("Reaction for issue created: %d/%d/%d", ctx.Repo.Repository.ID, issue.ID, reaction.ID)
case "unreact": case "unreact":
if err := models.DeleteIssueReaction(ctx.User, issue, form.Content); err != nil { if err := models.DeleteIssueReaction(ctx.User, issue, form.Content); err != nil {
ctx.Handle(500, "DeleteIssueReaction", err) ctx.ServerError("DeleteIssueReaction", err)
return 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) log.Trace("Reaction for issue removed: %d/%d", ctx.Repo.Repository.ID, issue.ID)
default: 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 return
} }
@ -1370,7 +1370,7 @@ func ChangeIssueReaction(ctx *context.Context, form auth.ReactionForm) {
"Reactions": issue.Reactions.GroupByType(), "Reactions": issue.Reactions.GroupByType(),
}) })
if err != nil { if err != nil {
ctx.Handle(500, "ChangeIssueReaction.HTMLString", err) ctx.ServerError("ChangeIssueReaction.HTMLString", err)
return return
} }
ctx.JSON(200, map[string]interface{}{ ctx.JSON(200, map[string]interface{}{
@ -1393,7 +1393,7 @@ func ChangeCommentReaction(ctx *context.Context, form auth.ReactionForm) {
} }
if ctx.HasError() { if ctx.HasError() {
ctx.Handle(500, "ChangeCommentReaction", errors.New(ctx.GetErrMsg())) ctx.ServerError("ChangeCommentReaction", errors.New(ctx.GetErrMsg()))
return 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) log.Trace("Reaction for comment created: %d/%d/%d/%d", ctx.Repo.Repository.ID, issue.ID, comment.ID, reaction.ID)
case "unreact": case "unreact":
if err := models.DeleteCommentReaction(ctx.User, issue, comment, form.Content); err != nil { if err := models.DeleteCommentReaction(ctx.User, issue, comment, form.Content); err != nil {
ctx.Handle(500, "DeleteCommentReaction", err) ctx.ServerError("DeleteCommentReaction", err)
return 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) log.Trace("Reaction for comment removed: %d/%d/%d", ctx.Repo.Repository.ID, issue.ID, comment.ID)
default: 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 return
} }
@ -1445,7 +1445,7 @@ func ChangeCommentReaction(ctx *context.Context, form auth.ReactionForm) {
"Reactions": comment.Reactions.GroupByType(), "Reactions": comment.Reactions.GroupByType(),
}) })
if err != nil { if err != nil {
ctx.Handle(500, "ChangeCommentReaction.HTMLString", err) ctx.ServerError("ChangeCommentReaction.HTMLString", err)
return return
} }
ctx.JSON(200, map[string]interface{}{ ctx.JSON(200, map[string]interface{}{

View File

@ -48,7 +48,7 @@ func InitializeLabels(ctx *context.Context, form auth.InitializeLabelsForm) {
} }
} }
if err := models.NewLabels(labels...); err != nil { if err := models.NewLabels(labels...); err != nil {
ctx.Handle(500, "NewLabels", err) ctx.ServerError("NewLabels", err)
return return
} }
ctx.Redirect(ctx.Repo.RepoLink + "/labels") ctx.Redirect(ctx.Repo.RepoLink + "/labels")
@ -58,7 +58,7 @@ func InitializeLabels(ctx *context.Context, form auth.InitializeLabelsForm) {
func RetrieveLabels(ctx *context.Context) { func RetrieveLabels(ctx *context.Context) {
labels, err := models.GetLabelsByRepoID(ctx.Repo.Repository.ID, ctx.Query("sort")) labels, err := models.GetLabelsByRepoID(ctx.Repo.Repository.ID, ctx.Query("sort"))
if err != nil { if err != nil {
ctx.Handle(500, "RetrieveLabels.GetLabels", err) ctx.ServerError("RetrieveLabels.GetLabels", err)
return return
} }
for _, l := range labels { for _, l := range labels {
@ -86,7 +86,7 @@ func NewLabel(ctx *context.Context, form auth.CreateLabelForm) {
Color: form.Color, Color: form.Color,
} }
if err := models.NewLabel(l); err != nil { if err := models.NewLabel(l); err != nil {
ctx.Handle(500, "NewLabel", err) ctx.ServerError("NewLabel", err)
return return
} }
ctx.Redirect(ctx.Repo.RepoLink + "/labels") ctx.Redirect(ctx.Repo.RepoLink + "/labels")
@ -100,7 +100,7 @@ func UpdateLabel(ctx *context.Context, form auth.CreateLabelForm) {
case models.IsErrLabelNotExist(err): case models.IsErrLabelNotExist(err):
ctx.Error(404) ctx.Error(404)
default: default:
ctx.Handle(500, "UpdateLabel", err) ctx.ServerError("UpdateLabel", err)
} }
return return
} }
@ -108,7 +108,7 @@ func UpdateLabel(ctx *context.Context, form auth.CreateLabelForm) {
l.Name = form.Title l.Name = form.Title
l.Color = form.Color l.Color = form.Color
if err := models.UpdateLabel(l); err != nil { if err := models.UpdateLabel(l); err != nil {
ctx.Handle(500, "UpdateLabel", err) ctx.ServerError("UpdateLabel", err)
return return
} }
ctx.Redirect(ctx.Repo.RepoLink + "/labels") ctx.Redirect(ctx.Repo.RepoLink + "/labels")
@ -139,7 +139,7 @@ func UpdateIssueLabel(ctx *context.Context) {
case "clear": case "clear":
for _, issue := range issues { for _, issue := range issues {
if err := issue.ClearLabels(ctx.User); err != nil { if err := issue.ClearLabels(ctx.User); err != nil {
ctx.Handle(500, "ClearLabels", err) ctx.ServerError("ClearLabels", err)
return return
} }
} }
@ -149,7 +149,7 @@ func UpdateIssueLabel(ctx *context.Context) {
if models.IsErrLabelNotExist(err) { if models.IsErrLabelNotExist(err) {
ctx.Error(404, "GetLabelByID") ctx.Error(404, "GetLabelByID")
} else { } else {
ctx.Handle(500, "GetLabelByID", err) ctx.ServerError("GetLabelByID", err)
} }
return return
} }
@ -168,14 +168,14 @@ func UpdateIssueLabel(ctx *context.Context) {
if action == "attach" { if action == "attach" {
for _, issue := range issues { for _, issue := range issues {
if err = issue.AddLabel(ctx.User, label); err != nil { if err = issue.AddLabel(ctx.User, label); err != nil {
ctx.Handle(500, "AddLabel", err) ctx.ServerError("AddLabel", err)
return return
} }
} }
} else { } else {
for _, issue := range issues { for _, issue := range issues {
if err = issue.RemoveLabel(ctx.User, label); err != nil { if err = issue.RemoveLabel(ctx.User, label); err != nil {
ctx.Handle(500, "RemoveLabel", err) ctx.ServerError("RemoveLabel", err)
return return
} }
} }

View File

@ -18,12 +18,12 @@ func IssueStopwatch(c *context.Context) {
return return
} }
if !c.Repo.CanUseTimetracker(issue, c.User) { if !c.Repo.CanUseTimetracker(issue, c.User) {
c.Handle(http.StatusNotFound, "CanUseTimetracker", nil) c.NotFound("CanUseTimetracker", nil)
return return
} }
if err := models.CreateOrStopIssueStopwatch(c.User, issue); err != nil { if err := models.CreateOrStopIssueStopwatch(c.User, issue); err != nil {
c.Handle(http.StatusInternalServerError, "CreateOrStopIssueStopwatch", err) c.ServerError("CreateOrStopIssueStopwatch", err)
return return
} }
@ -38,12 +38,12 @@ func CancelStopwatch(c *context.Context) {
return return
} }
if !c.Repo.CanUseTimetracker(issue, c.User) { if !c.Repo.CanUseTimetracker(issue, c.User) {
c.Handle(http.StatusNotFound, "CanUseTimetracker", nil) c.NotFound("CanUseTimetracker", nil)
return return
} }
if err := models.CancelStopwatch(c.User, issue); err != nil { if err := models.CancelStopwatch(c.User, issue); err != nil {
c.Handle(http.StatusInternalServerError, "CancelStopwatch", err) c.ServerError("CancelStopwatch", err)
return return
} }

View File

@ -20,7 +20,7 @@ func AddTimeManually(c *context.Context, form auth.AddTimeManuallyForm) {
return return
} }
if !c.Repo.CanUseTimetracker(issue, c.User) { if !c.Repo.CanUseTimetracker(issue, c.User) {
c.Handle(http.StatusNotFound, "CanUseTimetracker", nil) c.NotFound("CanUseTimetracker", nil)
return return
} }
url := issue.HTMLURL() 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 { if _, err := models.AddTime(c.User, issue, int64(total.Seconds())); err != nil {
c.Handle(http.StatusInternalServerError, "AddTime", err) c.ServerError("AddTime", err)
return return
} }

View File

@ -17,7 +17,7 @@ import (
func IssueWatch(c *context.Context) { func IssueWatch(c *context.Context) {
watch, err := strconv.ParseBool(c.Req.PostForm.Get("watch")) watch, err := strconv.ParseBool(c.Req.PostForm.Get("watch"))
if err != nil { if err != nil {
c.Handle(http.StatusInternalServerError, "watch is not bool", err) c.ServerError("watch is not bool", err)
return return
} }
@ -27,7 +27,7 @@ func IssueWatch(c *context.Context) {
} }
if err := models.CreateOrUpdateIssueWatch(c.User.ID, issue.ID, watch); err != nil { if err := models.CreateOrUpdateIssueWatch(c.User.ID, issue.ID, watch); err != nil {
c.Handle(http.StatusInternalServerError, "CreateOrUpdateIssueWatch", err) c.ServerError("CreateOrUpdateIssueWatch", err)
return return
} }

View File

@ -15,7 +15,7 @@ func SetEditorconfigIfExists(ctx *context.Context) {
if err != nil && !git.IsErrNotExist(err) { if err != nil && !git.IsErrNotExist(err) {
description := fmt.Sprintf("Error while getting .editorconfig file: %v", err) description := fmt.Sprintf("Error while getting .editorconfig file: %v", err)
if err := models.CreateRepositoryNotice(description); err != nil { if err := models.CreateRepositoryNotice(description); err != nil {
ctx.Handle(500, "ErrCreatingReporitoryNotice", err) ctx.ServerError("ErrCreatingReporitoryNotice", err)
} }
return return
} }
@ -47,6 +47,6 @@ func SetDiffViewStyle(ctx *context.Context) {
ctx.Data["IsSplitStyle"] = style == "split" ctx.Data["IsSplitStyle"] = style == "split"
if err := ctx.User.UpdateDiffViewStyle(style); err != nil { if err := ctx.User.UpdateDiffViewStyle(style); err != nil {
ctx.Handle(500, "ErrUpdateDiffViewStyle", err) ctx.ServerError("ErrUpdateDiffViewStyle", err)
} }
} }

View File

@ -50,15 +50,15 @@ func getForkRepository(ctx *context.Context) *models.Repository {
forkRepo, err := models.GetRepositoryByID(ctx.ParamsInt64(":repoid")) forkRepo, err := models.GetRepositoryByID(ctx.ParamsInt64(":repoid"))
if err != nil { if err != nil {
if models.IsErrRepoNotExist(err) { if models.IsErrRepoNotExist(err) {
ctx.Handle(404, "GetRepositoryByID", nil) ctx.NotFound("GetRepositoryByID", nil)
} else { } else {
ctx.Handle(500, "GetRepositoryByID", err) ctx.ServerError("GetRepositoryByID", err)
} }
return nil return nil
} }
if !forkRepo.CanBeForked() || !forkRepo.HasAccess(ctx.User) { if !forkRepo.CanBeForked() || !forkRepo.HasAccess(ctx.User) {
ctx.Handle(404, "getForkRepository", nil) ctx.NotFound("getForkRepository", nil)
return 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) canForkToUser := forkRepo.OwnerID != ctx.User.ID && !ctx.User.HasForkedRepo(forkRepo.ID)
if err = forkRepo.GetOwner(); err != nil { if err = forkRepo.GetOwner(); err != nil {
ctx.Handle(500, "GetOwner", err) ctx.ServerError("GetOwner", err)
return nil return nil
} }
ctx.Data["ForkFrom"] = forkRepo.Owner.Name + "/" + forkRepo.Name ctx.Data["ForkFrom"] = forkRepo.Owner.Name + "/" + forkRepo.Name
ctx.Data["ForkFromOwnerID"] = forkRepo.Owner.ID ctx.Data["ForkFromOwnerID"] = forkRepo.Owner.ID
if err := ctx.User.GetOwnedOrganizations(); err != nil { if err := ctx.User.GetOwnedOrganizations(); err != nil {
ctx.Handle(500, "GetOwnedOrganizations", err) ctx.ServerError("GetOwnedOrganizations", err)
return nil return nil
} }
var orgs []*models.User var orgs []*models.User
@ -103,7 +103,7 @@ func getForkRepository(ctx *context.Context) *models.Repository {
} }
traverseParentRepo, err = models.GetRepositoryByID(traverseParentRepo.ForkID) traverseParentRepo, err = models.GetRepositoryByID(traverseParentRepo.ForkID)
if err != nil { if err != nil {
ctx.Handle(500, "GetRepositoryByID", err) ctx.ServerError("GetRepositoryByID", err)
return nil return nil
} }
} }
@ -170,7 +170,7 @@ func ForkPost(ctx *context.Context, form auth.CreateRepoForm) {
} }
traverseParentRepo, err = models.GetRepositoryByID(traverseParentRepo.ForkID) traverseParentRepo, err = models.GetRepositoryByID(traverseParentRepo.ForkID)
if err != nil { if err != nil {
ctx.Handle(500, "GetRepositoryByID", err) ctx.ServerError("GetRepositoryByID", err)
return return
} }
} }
@ -179,7 +179,7 @@ func ForkPost(ctx *context.Context, form auth.CreateRepoForm) {
if ctxUser.IsOrganization() { if ctxUser.IsOrganization() {
isOwner, err := ctxUser.IsOwnedBy(ctx.User.ID) isOwner, err := ctxUser.IsOwnedBy(ctx.User.ID)
if err != nil { if err != nil {
ctx.Handle(500, "IsOwnedBy", err) ctx.ServerError("IsOwnedBy", err)
return return
} else if !isOwner { } else if !isOwner {
ctx.Error(403) ctx.Error(403)
@ -198,7 +198,7 @@ func ForkPost(ctx *context.Context, form auth.CreateRepoForm) {
case models.IsErrNamePatternNotAllowed(err): case models.IsErrNamePatternNotAllowed(err):
ctx.RenderWithErr(ctx.Tr("repo.form.name_pattern_not_allowed", err.(models.ErrNamePatternNotAllowed).Pattern), tplFork, &form) ctx.RenderWithErr(ctx.Tr("repo.form.name_pattern_not_allowed", err.(models.ErrNamePatternNotAllowed).Pattern), tplFork, &form)
default: default:
ctx.Handle(500, "ForkPost", err) ctx.ServerError("ForkPost", err)
} }
return return
} }
@ -211,9 +211,9 @@ func checkPullInfo(ctx *context.Context) *models.Issue {
issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index")) issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
if err != nil { if err != nil {
if models.IsErrIssueNotExist(err) { if models.IsErrIssueNotExist(err) {
ctx.Handle(404, "GetIssueByIndex", err) ctx.NotFound("GetIssueByIndex", err)
} else { } else {
ctx.Handle(500, "GetIssueByIndex", err) ctx.ServerError("GetIssueByIndex", err)
} }
return nil return nil
} }
@ -221,19 +221,19 @@ func checkPullInfo(ctx *context.Context) *models.Issue {
ctx.Data["Issue"] = issue ctx.Data["Issue"] = issue
if !issue.IsPull { if !issue.IsPull {
ctx.Handle(404, "ViewPullCommits", nil) ctx.NotFound("ViewPullCommits", nil)
return nil return nil
} }
if err = issue.PullRequest.GetHeadRepo(); err != nil { if err = issue.PullRequest.GetHeadRepo(); err != nil {
ctx.Handle(500, "GetHeadRepo", err) ctx.ServerError("GetHeadRepo", err)
return nil return nil
} }
if ctx.IsSigned { if ctx.IsSigned {
// Update issue-user. // Update issue-user.
if err = issue.ReadBy(ctx.User.ID); err != nil { if err = issue.ReadBy(ctx.User.ID); err != nil {
ctx.Handle(500, "ReadBy", err) ctx.ServerError("ReadBy", err)
return nil return nil
} }
} }
@ -258,7 +258,7 @@ func PrepareMergedViewPullInfo(ctx *context.Context, issue *models.Issue) {
var err error var err error
if err = pull.GetHeadRepo(); err != nil { if err = pull.GetHeadRepo(); err != nil {
ctx.Handle(500, "GetHeadRepo", err) ctx.ServerError("GetHeadRepo", err)
return return
} }
@ -267,24 +267,24 @@ func PrepareMergedViewPullInfo(ctx *context.Context, issue *models.Issue) {
mergedCommit, err := ctx.Repo.GitRepo.GetCommit(pull.MergedCommitID) mergedCommit, err := ctx.Repo.GitRepo.GetCommit(pull.MergedCommitID)
if err != nil { if err != nil {
ctx.Handle(500, "GetCommit", err) ctx.ServerError("GetCommit", err)
return return
} }
// the ID of the last commit in the PR (not including the merge commit) // the ID of the last commit in the PR (not including the merge commit)
endCommitID, err := mergedCommit.ParentID(mergedCommit.ParentCount() - 1) endCommitID, err := mergedCommit.ParentID(mergedCommit.ParentCount() - 1)
if err != nil { if err != nil {
ctx.Handle(500, "ParentID", err) ctx.ServerError("ParentID", err)
return return
} }
ctx.Data["NumCommits"], err = ctx.Repo.GitRepo.CommitsCountBetween(pull.MergeBase, endCommitID.String()) ctx.Data["NumCommits"], err = ctx.Repo.GitRepo.CommitsCountBetween(pull.MergeBase, endCommitID.String())
if err != nil { if err != nil {
ctx.Handle(500, "Repo.GitRepo.CommitsCountBetween", err) ctx.ServerError("Repo.GitRepo.CommitsCountBetween", err)
return return
} }
ctx.Data["NumFiles"], err = ctx.Repo.GitRepo.FilesCountBetween(pull.MergeBase, endCommitID.String()) ctx.Data["NumFiles"], err = ctx.Repo.GitRepo.FilesCountBetween(pull.MergeBase, endCommitID.String())
if err != nil { if err != nil {
ctx.Handle(500, "Repo.GitRepo.FilesCountBetween", err) ctx.ServerError("Repo.GitRepo.FilesCountBetween", err)
return return
} }
} }
@ -296,7 +296,7 @@ func PrepareViewPullInfo(ctx *context.Context, issue *models.Issue) *git.PullReq
var err error var err error
if err = pull.GetHeadRepo(); err != nil { if err = pull.GetHeadRepo(); err != nil {
ctx.Handle(500, "GetHeadRepo", err) ctx.ServerError("GetHeadRepo", err)
return nil return nil
} }
@ -306,7 +306,7 @@ func PrepareViewPullInfo(ctx *context.Context, issue *models.Issue) *git.PullReq
if pull.HeadRepo != nil { if pull.HeadRepo != nil {
headGitRepo, err = git.OpenRepository(pull.HeadRepo.RepoPath()) headGitRepo, err = git.OpenRepository(pull.HeadRepo.RepoPath())
if err != nil { if err != nil {
ctx.Handle(500, "OpenRepository", err) ctx.ServerError("OpenRepository", err)
return nil return nil
} }
} }
@ -330,7 +330,7 @@ func PrepareViewPullInfo(ctx *context.Context, issue *models.Issue) *git.PullReq
return nil return nil
} }
ctx.Handle(500, "GetPullRequestInfo", err) ctx.ServerError("GetPullRequestInfo", err)
return nil return nil
} }
ctx.Data["NumCommits"] = prInfo.Commits.Len() ctx.Data["NumCommits"] = prInfo.Commits.Len()
@ -360,17 +360,17 @@ func ViewPullCommits(ctx *context.Context) {
mergedCommit, err := ctx.Repo.GitRepo.GetCommit(pull.MergedCommitID) mergedCommit, err := ctx.Repo.GitRepo.GetCommit(pull.MergedCommitID)
if err != nil { if err != nil {
ctx.Handle(500, "Repo.GitRepo.GetCommit", err) ctx.ServerError("Repo.GitRepo.GetCommit", err)
return return
} }
endCommitID, err := mergedCommit.ParentID(mergedCommit.ParentCount() - 1) endCommitID, err := mergedCommit.ParentID(mergedCommit.ParentCount() - 1)
if err != nil { if err != nil {
ctx.Handle(500, "ParentID", err) ctx.ServerError("ParentID", err)
return return
} }
commits, err = ctx.Repo.GitRepo.CommitsBetweenIDs(endCommitID.String(), pull.MergeBase) commits, err = ctx.Repo.GitRepo.CommitsBetweenIDs(endCommitID.String(), pull.MergeBase)
if err != nil { if err != nil {
ctx.Handle(500, "Repo.GitRepo.CommitsBetweenIDs", err) ctx.ServerError("Repo.GitRepo.CommitsBetweenIDs", err)
return return
} }
} else { } else {
@ -378,7 +378,7 @@ func ViewPullCommits(ctx *context.Context) {
if ctx.Written() { if ctx.Written() {
return return
} else if prInfo == nil { } else if prInfo == nil {
ctx.Handle(404, "ViewPullCommits", nil) ctx.NotFound("ViewPullCommits", nil)
return return
} }
ctx.Data["Username"] = pull.HeadUserName ctx.Data["Username"] = pull.HeadUserName
@ -424,12 +424,12 @@ func ViewPullFiles(ctx *context.Context) {
startCommitID = pull.MergeBase startCommitID = pull.MergeBase
mergedCommit, err := ctx.Repo.GitRepo.GetCommit(pull.MergedCommitID) mergedCommit, err := ctx.Repo.GitRepo.GetCommit(pull.MergedCommitID)
if err != nil { if err != nil {
ctx.Handle(500, "GetCommit", err) ctx.ServerError("GetCommit", err)
return return
} }
endCommitSha, err := mergedCommit.ParentID(mergedCommit.ParentCount() - 1) endCommitSha, err := mergedCommit.ParentID(mergedCommit.ParentCount() - 1)
if err != nil { if err != nil {
ctx.Handle(500, "ParentID", err) ctx.ServerError("ParentID", err)
return return
} }
endCommitID = endCommitSha.String() endCommitID = endCommitSha.String()
@ -443,7 +443,7 @@ func ViewPullFiles(ctx *context.Context) {
if ctx.Written() { if ctx.Written() {
return return
} else if prInfo == nil { } else if prInfo == nil {
ctx.Handle(404, "ViewPullFiles", nil) ctx.NotFound("ViewPullFiles", nil)
return return
} }
@ -451,13 +451,13 @@ func ViewPullFiles(ctx *context.Context) {
headGitRepo, err := git.OpenRepository(headRepoPath) headGitRepo, err := git.OpenRepository(headRepoPath)
if err != nil { if err != nil {
ctx.Handle(500, "OpenRepository", err) ctx.ServerError("OpenRepository", err)
return return
} }
headCommitID, err := headGitRepo.GetBranchCommitID(pull.HeadBranch) headCommitID, err := headGitRepo.GetBranchCommitID(pull.HeadBranch)
if err != nil { if err != nil {
ctx.Handle(500, "GetBranchCommitID", err) ctx.ServerError("GetBranchCommitID", err)
return return
} }
@ -475,7 +475,7 @@ func ViewPullFiles(ctx *context.Context) {
startCommitID, endCommitID, setting.Git.MaxGitDiffLines, startCommitID, endCommitID, setting.Git.MaxGitDiffLines,
setting.Git.MaxGitDiffLineCharacters, setting.Git.MaxGitDiffFiles) setting.Git.MaxGitDiffLineCharacters, setting.Git.MaxGitDiffFiles)
if err != nil { if err != nil {
ctx.Handle(500, "GetDiffRange", err) ctx.ServerError("GetDiffRange", err)
return return
} }
ctx.Data["Diff"] = diff ctx.Data["Diff"] = diff
@ -483,7 +483,7 @@ func ViewPullFiles(ctx *context.Context) {
commit, err := gitRepo.GetCommit(endCommitID) commit, err := gitRepo.GetCommit(endCommitID)
if err != nil { if err != nil {
ctx.Handle(500, "GetCommit", err) ctx.ServerError("GetCommit", err)
return return
} }
@ -503,23 +503,23 @@ func MergePullRequest(ctx *context.Context, form auth.MergePullRequestForm) {
return return
} }
if issue.IsClosed { if issue.IsClosed {
ctx.Handle(404, "MergePullRequest", nil) ctx.NotFound("MergePullRequest", nil)
return return
} }
pr, err := models.GetPullRequestByIssueID(issue.ID) pr, err := models.GetPullRequestByIssueID(issue.ID)
if err != nil { if err != nil {
if models.IsErrPullRequestNotExist(err) { if models.IsErrPullRequestNotExist(err) {
ctx.Handle(404, "GetPullRequestByIssueID", nil) ctx.NotFound("GetPullRequestByIssueID", nil)
} else { } else {
ctx.Handle(500, "GetPullRequestByIssueID", err) ctx.ServerError("GetPullRequestByIssueID", err)
} }
return return
} }
pr.Issue = issue pr.Issue = issue
if !pr.CanAutoMerge() || pr.HasMerged { if !pr.CanAutoMerge() || pr.HasMerged {
ctx.Handle(404, "MergePullRequest", nil) ctx.NotFound("MergePullRequest", nil)
return return
} }
@ -552,7 +552,7 @@ func MergePullRequest(ctx *context.Context, form auth.MergePullRequestForm) {
ctx.Redirect(ctx.Repo.RepoLink + "/pulls/" + com.ToStr(pr.Index)) ctx.Redirect(ctx.Repo.RepoLink + "/pulls/" + com.ToStr(pr.Index))
return return
} }
ctx.Handle(500, "Merge", err) ctx.ServerError("Merge", err)
return return
} }
@ -580,12 +580,12 @@ func ParseCompareInfo(ctx *context.Context) (*models.User, *models.Repository, *
) )
infoPath, err = url.QueryUnescape(ctx.Params("*")) infoPath, err = url.QueryUnescape(ctx.Params("*"))
if err != nil { if err != nil {
ctx.Handle(404, "QueryUnescape", err) ctx.NotFound("QueryUnescape", err)
} }
infos := strings.Split(infoPath, "...") infos := strings.Split(infoPath, "...")
if len(infos) != 2 { if len(infos) != 2 {
log.Trace("ParseCompareInfo[%d]: not enough compared branches information %s", baseRepo.ID, infos) 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, "", "" return nil, nil, nil, nil, "", ""
} }
@ -603,16 +603,16 @@ func ParseCompareInfo(ctx *context.Context) (*models.User, *models.Repository, *
headUser, err = models.GetUserByName(headInfos[0]) headUser, err = models.GetUserByName(headInfos[0])
if err != nil { if err != nil {
if models.IsErrUserNotExist(err) { if models.IsErrUserNotExist(err) {
ctx.Handle(404, "GetUserByName", nil) ctx.NotFound("GetUserByName", nil)
} else { } else {
ctx.Handle(500, "GetUserByName", err) ctx.ServerError("GetUserByName", err)
} }
return nil, nil, nil, nil, "", "" return nil, nil, nil, nil, "", ""
} }
headBranch = headInfos[1] headBranch = headInfos[1]
isSameRepo = headUser.ID == ctx.Repo.Owner.ID isSameRepo = headUser.ID == ctx.Repo.Owner.ID
} else { } else {
ctx.Handle(404, "CompareAndPullRequest", nil) ctx.NotFound("CompareAndPullRequest", nil)
return nil, nil, nil, nil, "", "" return nil, nil, nil, nil, "", ""
} }
ctx.Data["HeadUser"] = headUser ctx.Data["HeadUser"] = headUser
@ -621,7 +621,7 @@ func ParseCompareInfo(ctx *context.Context) (*models.User, *models.Repository, *
// Check if base branch is valid. // Check if base branch is valid.
if !ctx.Repo.GitRepo.IsBranchExist(baseBranch) { if !ctx.Repo.GitRepo.IsBranchExist(baseBranch) {
ctx.Handle(404, "IsBranchExist", nil) ctx.NotFound("IsBranchExist", nil)
return nil, nil, nil, 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) headRepo, has := models.HasForkedRepo(headUser.ID, baseRepo.ID)
if !has && !isSameRepo { if !has && !isSameRepo {
log.Trace("ParseCompareInfo[%d]: does not have fork or in same repository", baseRepo.ID) 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, "", "" return nil, nil, nil, nil, "", ""
} }
@ -640,33 +640,33 @@ func ParseCompareInfo(ctx *context.Context) (*models.User, *models.Repository, *
} else { } else {
headGitRepo, err = git.OpenRepository(models.RepoPath(headUser.Name, headRepo.Name)) headGitRepo, err = git.OpenRepository(models.RepoPath(headUser.Name, headRepo.Name))
if err != nil { if err != nil {
ctx.Handle(500, "OpenRepository", err) ctx.ServerError("OpenRepository", err)
return nil, nil, nil, nil, "", "" return nil, nil, nil, nil, "", ""
} }
} }
if !ctx.User.IsWriterOfRepo(headRepo) && !ctx.User.IsAdmin { if !ctx.User.IsWriterOfRepo(headRepo) && !ctx.User.IsAdmin {
log.Trace("ParseCompareInfo[%d]: does not have write access or site admin", baseRepo.ID) 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, "", "" return nil, nil, nil, nil, "", ""
} }
// Check if head branch is valid. // Check if head branch is valid.
if !headGitRepo.IsBranchExist(headBranch) { if !headGitRepo.IsBranchExist(headBranch) {
ctx.Handle(404, "IsBranchExist", nil) ctx.NotFound("IsBranchExist", nil)
return nil, nil, nil, nil, "", "" return nil, nil, nil, nil, "", ""
} }
headBranches, err := headGitRepo.GetBranches() headBranches, err := headGitRepo.GetBranches()
if err != nil { if err != nil {
ctx.Handle(500, "GetBranches", err) ctx.ServerError("GetBranches", err)
return nil, nil, nil, nil, "", "" return nil, nil, nil, nil, "", ""
} }
ctx.Data["HeadBranches"] = headBranches ctx.Data["HeadBranches"] = headBranches
prInfo, err := headGitRepo.GetPullRequestInfo(models.RepoPath(baseRepo.Owner.Name, baseRepo.Name), baseBranch, headBranch) prInfo, err := headGitRepo.GetPullRequestInfo(models.RepoPath(baseRepo.Owner.Name, baseRepo.Name), baseBranch, headBranch)
if err != nil { if err != nil {
ctx.Handle(500, "GetPullRequestInfo", err) ctx.ServerError("GetPullRequestInfo", err)
return nil, nil, nil, nil, "", "" return nil, nil, nil, nil, "", ""
} }
ctx.Data["BeforeCommitID"] = prInfo.MergeBase ctx.Data["BeforeCommitID"] = prInfo.MergeBase
@ -693,7 +693,7 @@ func PrepareCompareDiff(
headCommitID, err := headGitRepo.GetBranchCommitID(headBranch) headCommitID, err := headGitRepo.GetBranchCommitID(headBranch)
if err != nil { if err != nil {
ctx.Handle(500, "GetBranchCommitID", err) ctx.ServerError("GetBranchCommitID", err)
return false return false
} }
ctx.Data["AfterCommitID"] = headCommitID ctx.Data["AfterCommitID"] = headCommitID
@ -707,7 +707,7 @@ func PrepareCompareDiff(
prInfo.MergeBase, headCommitID, setting.Git.MaxGitDiffLines, prInfo.MergeBase, headCommitID, setting.Git.MaxGitDiffLines,
setting.Git.MaxGitDiffLineCharacters, setting.Git.MaxGitDiffFiles) setting.Git.MaxGitDiffLineCharacters, setting.Git.MaxGitDiffFiles)
if err != nil { if err != nil {
ctx.Handle(500, "GetDiffRange", err) ctx.ServerError("GetDiffRange", err)
return false return false
} }
ctx.Data["Diff"] = diff ctx.Data["Diff"] = diff
@ -715,7 +715,7 @@ func PrepareCompareDiff(
headCommit, err := headGitRepo.GetCommit(headCommitID) headCommit, err := headGitRepo.GetCommit(headCommitID)
if err != nil { if err != nil {
ctx.Handle(500, "GetCommit", err) ctx.ServerError("GetCommit", err)
return false return false
} }
@ -753,7 +753,7 @@ func CompareAndPullRequest(ctx *context.Context) {
pr, err := models.GetUnmergedPullRequest(headRepo.ID, ctx.Repo.Repository.ID, headBranch, baseBranch) pr, err := models.GetUnmergedPullRequest(headRepo.ID, ctx.Repo.Repository.ID, headBranch, baseBranch)
if err != nil { if err != nil {
if !models.IsErrPullRequestNotExist(err) { if !models.IsErrPullRequestNotExist(err) {
ctx.Handle(500, "GetUnmergedPullRequest", err) ctx.ServerError("GetUnmergedPullRequest", err)
return return
} }
} else { } else {
@ -822,7 +822,7 @@ func CompareAndPullRequestPost(ctx *context.Context, form auth.CreateIssueForm)
patch, err := headGitRepo.GetPatch(prInfo.MergeBase, headBranch) patch, err := headGitRepo.GetPatch(prInfo.MergeBase, headBranch)
if err != nil { if err != nil {
ctx.Handle(500, "GetPatch", err) ctx.ServerError("GetPatch", err)
return 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 // FIXME: check error in the case two people send pull request at almost same time, give nice error prompt
// instead of 500. // instead of 500.
if err := models.NewPullRequest(repo, pullIssue, labelIDs, attachments, pullRequest, patch); err != nil { if err := models.NewPullRequest(repo, pullIssue, labelIDs, attachments, pullRequest, patch); err != nil {
ctx.Handle(500, "NewPullRequest", err) ctx.ServerError("NewPullRequest", err)
return return
} else if err := pullRequest.PushToBaseRepo(); err != nil { } else if err := pullRequest.PushToBaseRepo(); err != nil {
ctx.Handle(500, "PushToBaseRepo", err) ctx.ServerError("PushToBaseRepo", err)
return return
} }
@ -889,7 +889,7 @@ func TriggerTask(ctx *context.Context) {
if models.IsErrUserNotExist(err) { if models.IsErrUserNotExist(err) {
ctx.Error(404) ctx.Error(404)
} else { } else {
ctx.Handle(500, "GetUserByID", err) ctx.ServerError("GetUserByID", err)
} }
return return
} }
@ -911,36 +911,36 @@ func CleanUpPullRequest(ctx *context.Context) {
pr, err := models.GetPullRequestByIssueID(issue.ID) pr, err := models.GetPullRequestByIssueID(issue.ID)
if err != nil { if err != nil {
if models.IsErrPullRequestNotExist(err) { if models.IsErrPullRequestNotExist(err) {
ctx.Handle(404, "GetPullRequestByIssueID", nil) ctx.NotFound("GetPullRequestByIssueID", nil)
} else { } else {
ctx.Handle(500, "GetPullRequestByIssueID", err) ctx.ServerError("GetPullRequestByIssueID", err)
} }
return return
} }
// Allow cleanup only for merged PR // Allow cleanup only for merged PR
if !pr.HasMerged { if !pr.HasMerged {
ctx.Handle(404, "CleanUpPullRequest", nil) ctx.NotFound("CleanUpPullRequest", nil)
return return
} }
if err = pr.GetHeadRepo(); err != nil { if err = pr.GetHeadRepo(); err != nil {
ctx.Handle(500, "GetHeadRepo", err) ctx.ServerError("GetHeadRepo", err)
return return
} else if pr.HeadRepo == nil { } else if pr.HeadRepo == nil {
// Forked repository has already been deleted // Forked repository has already been deleted
ctx.Handle(404, "CleanUpPullRequest", nil) ctx.NotFound("CleanUpPullRequest", nil)
return return
} else if pr.GetBaseRepo(); err != nil { } else if pr.GetBaseRepo(); err != nil {
ctx.Handle(500, "GetBaseRepo", err) ctx.ServerError("GetBaseRepo", err)
return return
} else if pr.HeadRepo.GetOwner(); err != nil { } else if pr.HeadRepo.GetOwner(); err != nil {
ctx.Handle(500, "HeadRepo.GetOwner", err) ctx.ServerError("HeadRepo.GetOwner", err)
return return
} }
if !ctx.User.IsWriterOfRepo(pr.HeadRepo) { if !ctx.User.IsWriterOfRepo(pr.HeadRepo) {
ctx.Handle(403, "CleanUpPullRequest", nil) ctx.NotFound("CleanUpPullRequest", nil)
return return
} }
@ -948,13 +948,13 @@ func CleanUpPullRequest(ctx *context.Context) {
gitRepo, err := git.OpenRepository(pr.HeadRepo.RepoPath()) gitRepo, err := git.OpenRepository(pr.HeadRepo.RepoPath())
if err != nil { 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 return
} }
gitBaseRepo, err := git.OpenRepository(pr.BaseRepo.RepoPath()) gitBaseRepo, err := git.OpenRepository(pr.BaseRepo.RepoPath())
if err != nil { 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 return
} }
@ -1033,16 +1033,16 @@ func DownloadPullDiff(ctx *context.Context) {
issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index")) issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
if err != nil { if err != nil {
if models.IsErrIssueNotExist(err) { if models.IsErrIssueNotExist(err) {
ctx.Handle(404, "GetIssueByIndex", err) ctx.NotFound("GetIssueByIndex", err)
} else { } else {
ctx.Handle(500, "GetIssueByIndex", err) ctx.ServerError("GetIssueByIndex", err)
} }
return return
} }
// Return not found if it's not a pull request // Return not found if it's not a pull request
if !issue.IsPull { if !issue.IsPull {
ctx.Handle(404, "DownloadPullDiff", ctx.NotFound("DownloadPullDiff",
fmt.Errorf("Issue is not a pull request")) fmt.Errorf("Issue is not a pull request"))
return return
} }
@ -1050,12 +1050,12 @@ func DownloadPullDiff(ctx *context.Context) {
pr := issue.PullRequest pr := issue.PullRequest
if err = pr.GetBaseRepo(); err != nil { if err = pr.GetBaseRepo(); err != nil {
ctx.Handle(500, "GetBaseRepo", err) ctx.ServerError("GetBaseRepo", err)
return return
} }
patch, err := pr.BaseRepo.PatchPath(pr.Index) patch, err := pr.BaseRepo.PatchPath(pr.Index)
if err != nil { if err != nil {
ctx.Handle(500, "PatchPath", err) ctx.ServerError("PatchPath", err)
return return
} }
@ -1067,16 +1067,16 @@ func DownloadPullPatch(ctx *context.Context) {
issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index")) issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
if err != nil { if err != nil {
if models.IsErrIssueNotExist(err) { if models.IsErrIssueNotExist(err) {
ctx.Handle(404, "GetIssueByIndex", err) ctx.NotFound("GetIssueByIndex", err)
} else { } else {
ctx.Handle(500, "GetIssueByIndex", err) ctx.ServerError("GetIssueByIndex", err)
} }
return return
} }
// Return not found if it's not a pull request // Return not found if it's not a pull request
if !issue.IsPull { if !issue.IsPull {
ctx.Handle(404, "DownloadPullDiff", ctx.NotFound("DownloadPullDiff",
fmt.Errorf("Issue is not a pull request")) fmt.Errorf("Issue is not a pull request"))
return return
} }
@ -1084,25 +1084,25 @@ func DownloadPullPatch(ctx *context.Context) {
pr := issue.PullRequest pr := issue.PullRequest
if err = pr.GetHeadRepo(); err != nil { if err = pr.GetHeadRepo(); err != nil {
ctx.Handle(500, "GetHeadRepo", err) ctx.ServerError("GetHeadRepo", err)
return return
} }
headGitRepo, err := git.OpenRepository(pr.HeadRepo.RepoPath()) headGitRepo, err := git.OpenRepository(pr.HeadRepo.RepoPath())
if err != nil { if err != nil {
ctx.Handle(500, "OpenRepository", err) ctx.ServerError("OpenRepository", err)
return return
} }
patch, err := headGitRepo.GetFormatPatch(pr.MergeBase, pr.HeadBranch) patch, err := headGitRepo.GetFormatPatch(pr.MergeBase, pr.HeadBranch)
if err != nil { if err != nil {
ctx.Handle(500, "GetFormatPatch", err) ctx.ServerError("GetFormatPatch", err)
return return
} }
_, err = io.Copy(ctx, patch) _, err = io.Copy(ctx, patch)
if err != nil { if err != nil {
ctx.Handle(500, "io.Copy", err) ctx.ServerError("io.Copy", err)
return return
} }
} }

View File

@ -72,19 +72,19 @@ func Releases(ctx *context.Context) {
releases, err := models.GetReleasesByRepoID(ctx.Repo.Repository.ID, opts, page, limit) releases, err := models.GetReleasesByRepoID(ctx.Repo.Repository.ID, opts, page, limit)
if err != nil { if err != nil {
ctx.Handle(500, "GetReleasesByRepoID", err) ctx.ServerError("GetReleasesByRepoID", err)
return return
} }
count, err := models.GetReleaseCountByRepoID(ctx.Repo.Repository.ID, opts) count, err := models.GetReleaseCountByRepoID(ctx.Repo.Repository.ID, opts)
if err != nil { if err != nil {
ctx.Handle(500, "GetReleaseCountByRepoID", err) ctx.ServerError("GetReleaseCountByRepoID", err)
return return
} }
err = models.GetReleaseAttachments(releases...) err = models.GetReleaseAttachments(releases...)
if err != nil { if err != nil {
ctx.Handle(500, "GetReleaseAttachments", err) ctx.ServerError("GetReleaseAttachments", err)
return return
} }
@ -103,14 +103,14 @@ func Releases(ctx *context.Context) {
if models.IsErrUserNotExist(err) { if models.IsErrUserNotExist(err) {
r.Publisher = models.NewGhostUser() r.Publisher = models.NewGhostUser()
} else { } else {
ctx.Handle(500, "GetUserByID", err) ctx.ServerError("GetUserByID", err)
return return
} }
} }
cacheUsers[r.PublisherID] = r.Publisher cacheUsers[r.PublisherID] = r.Publisher
} }
if err := calReleaseNumCommitsBehind(ctx.Repo, r, countCache); err != nil { if err := calReleaseNumCommitsBehind(ctx.Repo, r, countCache); err != nil {
ctx.Handle(500, "calReleaseNumCommitsBehind", err) ctx.ServerError("calReleaseNumCommitsBehind", err)
return return
} }
r.Note = markdown.RenderString(r.Note, ctx.Repo.RepoLink, ctx.Repo.Repository.ComposeMetas()) 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) rel, err := models.GetRelease(ctx.Repo.Repository.ID, form.TagName)
if err != nil { if err != nil {
if !models.IsErrReleaseNotExist(err) { if !models.IsErrReleaseNotExist(err) {
ctx.Handle(500, "GetRelease", err) ctx.ServerError("GetRelease", err)
return return
} }
@ -178,7 +178,7 @@ func NewReleasePost(ctx *context.Context, form auth.NewReleaseForm) {
case models.IsErrInvalidTagName(err): case models.IsErrInvalidTagName(err):
ctx.RenderWithErr(ctx.Tr("repo.release.tag_name_invalid"), tplReleaseNew, &form) ctx.RenderWithErr(ctx.Tr("repo.release.tag_name_invalid"), tplReleaseNew, &form)
default: default:
ctx.Handle(500, "CreateRelease", err) ctx.ServerError("CreateRelease", err)
} }
return return
} }
@ -199,7 +199,7 @@ func NewReleasePost(ctx *context.Context, form auth.NewReleaseForm) {
if err = models.UpdateRelease(ctx.Repo.GitRepo, rel, attachmentUUIDs); err != nil { if err = models.UpdateRelease(ctx.Repo.GitRepo, rel, attachmentUUIDs); err != nil {
ctx.Data["Err_TagName"] = true ctx.Data["Err_TagName"] = true
ctx.Handle(500, "UpdateRelease", err) ctx.ServerError("UpdateRelease", err)
return return
} }
} }
@ -219,9 +219,9 @@ func EditRelease(ctx *context.Context) {
rel, err := models.GetRelease(ctx.Repo.Repository.ID, tagName) rel, err := models.GetRelease(ctx.Repo.Repository.ID, tagName)
if err != nil { if err != nil {
if models.IsErrReleaseNotExist(err) { if models.IsErrReleaseNotExist(err) {
ctx.Handle(404, "GetRelease", err) ctx.NotFound("GetRelease", err)
} else { } else {
ctx.Handle(500, "GetRelease", err) ctx.ServerError("GetRelease", err)
} }
return return
} }
@ -246,14 +246,14 @@ func EditReleasePost(ctx *context.Context, form auth.EditReleaseForm) {
rel, err := models.GetRelease(ctx.Repo.Repository.ID, tagName) rel, err := models.GetRelease(ctx.Repo.Repository.ID, tagName)
if err != nil { if err != nil {
if models.IsErrReleaseNotExist(err) { if models.IsErrReleaseNotExist(err) {
ctx.Handle(404, "GetRelease", err) ctx.NotFound("GetRelease", err)
} else { } else {
ctx.Handle(500, "GetRelease", err) ctx.ServerError("GetRelease", err)
} }
return return
} }
if rel.IsTag { if rel.IsTag {
ctx.Handle(404, "GetRelease", err) ctx.NotFound("GetRelease", err)
return return
} }
ctx.Data["tag_name"] = rel.TagName 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.IsDraft = len(form.Draft) > 0
rel.IsPrerelease = form.Prerelease rel.IsPrerelease = form.Prerelease
if err = models.UpdateRelease(ctx.Repo.GitRepo, rel, attachmentUUIDs); err != nil { if err = models.UpdateRelease(ctx.Repo.GitRepo, rel, attachmentUUIDs); err != nil {
ctx.Handle(500, "UpdateRelease", err) ctx.ServerError("UpdateRelease", err)
return return
} }
ctx.Redirect(ctx.Repo.RepoLink + "/releases") ctx.Redirect(ctx.Repo.RepoLink + "/releases")

View File

@ -31,14 +31,14 @@ const (
// MustBeNotBare render when a repo is a bare git dir // MustBeNotBare render when a repo is a bare git dir
func MustBeNotBare(ctx *context.Context) { func MustBeNotBare(ctx *context.Context) {
if ctx.Repo.Repository.IsBare { if ctx.Repo.Repository.IsBare {
ctx.Handle(404, "MustBeNotBare", nil) ctx.NotFound("MustBeNotBare", nil)
} }
} }
// MustBeEditable check that repo can be edited // MustBeEditable check that repo can be edited
func MustBeEditable(ctx *context.Context) { func MustBeEditable(ctx *context.Context) {
if !ctx.Repo.Repository.CanEnableEditor() || ctx.Repo.IsViewCommit { if !ctx.Repo.Repository.CanEnableEditor() || ctx.Repo.IsViewCommit {
ctx.Handle(404, "", nil) ctx.NotFound("", nil)
return return
} }
} }
@ -46,14 +46,14 @@ func MustBeEditable(ctx *context.Context) {
// MustBeAbleToUpload check that repo can be uploaded to // MustBeAbleToUpload check that repo can be uploaded to
func MustBeAbleToUpload(ctx *context.Context) { func MustBeAbleToUpload(ctx *context.Context) {
if !setting.Repository.Upload.Enabled { if !setting.Repository.Upload.Enabled {
ctx.Handle(404, "", nil) ctx.NotFound("", nil)
} }
} }
func checkContextUser(ctx *context.Context, uid int64) *models.User { func checkContextUser(ctx *context.Context, uid int64) *models.User {
orgs, err := models.GetOwnedOrgsByUserIDDesc(ctx.User.ID, "updated_unix") orgs, err := models.GetOwnedOrgsByUserIDDesc(ctx.User.ID, "updated_unix")
if err != nil { if err != nil {
ctx.Handle(500, "GetOwnedOrgsByUserIDDesc", err) ctx.ServerError("GetOwnedOrgsByUserIDDesc", err)
return nil return nil
} }
ctx.Data["Orgs"] = orgs ctx.Data["Orgs"] = orgs
@ -69,7 +69,7 @@ func checkContextUser(ctx *context.Context, uid int64) *models.User {
} }
if err != nil { if err != nil {
ctx.Handle(500, "GetUserByID", fmt.Errorf("[%d]: %v", uid, err)) ctx.ServerError("GetUserByID", fmt.Errorf("[%d]: %v", uid, err))
return nil return nil
} }
@ -81,7 +81,7 @@ func checkContextUser(ctx *context.Context, uid int64) *models.User {
if !ctx.User.IsAdmin { if !ctx.User.IsAdmin {
isOwner, err := org.IsOwnedBy(ctx.User.ID) isOwner, err := org.IsOwnedBy(ctx.User.ID)
if err != nil { if err != nil {
ctx.Handle(500, "IsOwnedBy", err) ctx.ServerError("IsOwnedBy", err)
return nil return nil
} else if !isOwner { } else if !isOwner {
ctx.Error(403) ctx.Error(403)
@ -143,7 +143,7 @@ func handleCreateError(ctx *context.Context, owner *models.User, err error, name
ctx.Data["Err_RepoName"] = true ctx.Data["Err_RepoName"] = true
ctx.RenderWithErr(ctx.Tr("repo.form.name_pattern_not_allowed", err.(models.ErrNamePatternNotAllowed).Pattern), tpl, form) ctx.RenderWithErr(ctx.Tr("repo.form.name_pattern_not_allowed", err.(models.ErrNamePatternNotAllowed).Pattern), tpl, form)
default: 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: case addrErr.IsInvalidPath:
ctx.RenderWithErr(ctx.Tr("repo.migrate.invalid_local_path"), tplMigrate, &form) ctx.RenderWithErr(ctx.Tr("repo.migrate.invalid_local_path"), tplMigrate, &form)
default: default:
ctx.Handle(500, "Unknown error", err) ctx.ServerError("Unknown error", err)
} }
} else { } else {
ctx.Handle(500, "ParseRemoteAddr", err) ctx.ServerError("ParseRemoteAddr", err)
} }
return return
} }
@ -303,7 +303,7 @@ func Action(ctx *context.Context) {
} }
if err != nil { 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 return
} }
@ -342,7 +342,7 @@ func Download(ctx *context.Context) {
if !com.IsDir(archivePath) { if !com.IsDir(archivePath) {
if err := os.MkdirAll(archivePath, os.ModePerm); err != nil { 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 return
} }
} }
@ -356,30 +356,30 @@ func Download(ctx *context.Context) {
if gitRepo.IsBranchExist(refName) { if gitRepo.IsBranchExist(refName) {
commit, err = gitRepo.GetBranchCommit(refName) commit, err = gitRepo.GetBranchCommit(refName)
if err != nil { if err != nil {
ctx.Handle(500, "GetBranchCommit", err) ctx.ServerError("GetBranchCommit", err)
return return
} }
} else if gitRepo.IsTagExist(refName) { } else if gitRepo.IsTagExist(refName) {
commit, err = gitRepo.GetTagCommit(refName) commit, err = gitRepo.GetTagCommit(refName)
if err != nil { if err != nil {
ctx.Handle(500, "GetTagCommit", err) ctx.ServerError("GetTagCommit", err)
return return
} }
} else if len(refName) >= 4 && len(refName) <= 40 { } else if len(refName) >= 4 && len(refName) <= 40 {
commit, err = gitRepo.GetCommit(refName) commit, err = gitRepo.GetCommit(refName)
if err != nil { if err != nil {
ctx.Handle(404, "GetCommit", nil) ctx.NotFound("GetCommit", nil)
return return
} }
} else { } else {
ctx.Handle(404, "Download", nil) ctx.NotFound("Download", nil)
return return
} }
archivePath = path.Join(archivePath, base.ShortSha(commit.ID.String())+ext) archivePath = path.Join(archivePath, base.ShortSha(commit.ID.String())+ext)
if !com.IsFile(archivePath) { if !com.IsFile(archivePath) {
if err := commit.CreateArchive(archivePath, archiveType); err != nil { if err := commit.CreateArchive(archivePath, archiveType); err != nil {
ctx.Handle(500, "Download -> CreateArchive "+archivePath, err) ctx.ServerError("Download -> CreateArchive "+archivePath, err)
return return
} }
} }

View File

@ -31,7 +31,7 @@ func Search(ctx *context.Context) {
} }
total, searchResults, err := search.PerformSearch(ctx.Repo.Repository.ID, keyword, page, setting.UI.RepoSearchPagingNum) total, searchResults, err := search.PerformSearch(ctx.Repo.Repository.ID, keyword, page, setting.UI.RepoSearchPagingNum)
if err != nil { if err != nil {
ctx.Handle(500, "SearchResults", err) ctx.ServerError("SearchResults", err)
return return
} }
ctx.Data["Keyword"] = keyword ctx.Data["Keyword"] = keyword

View File

@ -67,14 +67,14 @@ func SettingsPost(ctx *context.Context, form auth.RepoSettingForm) {
case models.IsErrNamePatternNotAllowed(err): case models.IsErrNamePatternNotAllowed(err):
ctx.RenderWithErr(ctx.Tr("repo.form.name_pattern_not_allowed", err.(models.ErrNamePatternNotAllowed).Pattern), tplSettingsOptions, &form) ctx.RenderWithErr(ctx.Tr("repo.form.name_pattern_not_allowed", err.(models.ErrNamePatternNotAllowed).Pattern), tplSettingsOptions, &form)
default: default:
ctx.Handle(500, "ChangeRepositoryName", err) ctx.ServerError("ChangeRepositoryName", err)
} }
return return
} }
err := models.NewRepoRedirect(ctx.Repo.Owner.ID, repo.ID, repo.Name, newRepoName) err := models.NewRepoRedirect(ctx.Repo.Owner.ID, repo.ID, repo.Name, newRepoName)
if err != nil { if err != nil {
ctx.Handle(500, "NewRepoRedirect", err) ctx.ServerError("NewRepoRedirect", err)
return return
} }
@ -94,7 +94,7 @@ func SettingsPost(ctx *context.Context, form auth.RepoSettingForm) {
visibilityChanged := repo.IsPrivate != form.Private visibilityChanged := repo.IsPrivate != form.Private
repo.IsPrivate = form.Private repo.IsPrivate = form.Private
if err := models.UpdateRepository(repo, visibilityChanged); err != nil { if err := models.UpdateRepository(repo, visibilityChanged); err != nil {
ctx.Handle(500, "UpdateRepository", err) ctx.ServerError("UpdateRepository", err)
return return
} }
log.Trace("Repository basic settings updated: %s/%s", ctx.Repo.Owner.Name, repo.Name) 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": case "mirror":
if !repo.IsMirror { if !repo.IsMirror {
ctx.Handle(404, "", nil) ctx.NotFound("", nil)
return return
} }
@ -127,7 +127,7 @@ func SettingsPost(ctx *context.Context, form auth.RepoSettingForm) {
} }
} }
if err := ctx.Repo.Mirror.SaveAddress(form.MirrorAddress); err != nil { if err := ctx.Repo.Mirror.SaveAddress(form.MirrorAddress); err != nil {
ctx.Handle(500, "SaveAddress", err) ctx.ServerError("SaveAddress", err)
return return
} }
@ -136,7 +136,7 @@ func SettingsPost(ctx *context.Context, form auth.RepoSettingForm) {
case "mirror-sync": case "mirror-sync":
if !repo.IsMirror { if !repo.IsMirror {
ctx.Handle(404, "", nil) ctx.NotFound("", nil)
return return
} }
@ -221,7 +221,7 @@ func SettingsPost(ctx *context.Context, form auth.RepoSettingForm) {
} }
if err := models.UpdateRepositoryUnits(repo, units); err != nil { if err := models.UpdateRepositoryUnits(repo, units); err != nil {
ctx.Handle(500, "UpdateRepositoryUnits", err) ctx.ServerError("UpdateRepositoryUnits", err)
return return
} }
log.Trace("Repository advanced settings updated: %s/%s", ctx.Repo.Owner.Name, repo.Name) 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 repo.IsMirror = false
if _, err := models.CleanUpMigrateInfo(repo); err != nil { if _, err := models.CleanUpMigrateInfo(repo); err != nil {
ctx.Handle(500, "CleanUpMigrateInfo", err) ctx.ServerError("CleanUpMigrateInfo", err)
return return
} else if err = models.DeleteMirrorByRepoID(ctx.Repo.Repository.ID); err != nil { } else if err = models.DeleteMirrorByRepoID(ctx.Repo.Repository.ID); err != nil {
ctx.Handle(500, "DeleteMirrorByRepoID", err) ctx.ServerError("DeleteMirrorByRepoID", err)
return return
} }
log.Trace("Repository converted from mirror to regular: %s/%s", ctx.Repo.Owner.Name, repo.Name) 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") newOwner := ctx.Query("new_owner_name")
isExist, err := models.IsUserExist(0, newOwner) isExist, err := models.IsUserExist(0, newOwner)
if err != nil { if err != nil {
ctx.Handle(500, "IsUserExist", err) ctx.ServerError("IsUserExist", err)
return return
} else if !isExist { } else if !isExist {
ctx.RenderWithErr(ctx.Tr("form.enterred_invalid_owner_name"), tplSettingsOptions, nil) 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) { if models.IsErrRepoAlreadyExist(err) {
ctx.RenderWithErr(ctx.Tr("repo.settings.new_owner_has_same_repo"), tplSettingsOptions, nil) ctx.RenderWithErr(ctx.Tr("repo.settings.new_owner_has_same_repo"), tplSettingsOptions, nil)
} else { } else {
ctx.Handle(500, "TransferOwnership", err) ctx.ServerError("TransferOwnership", err)
} }
return 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 { if err := models.DeleteRepository(ctx.User, ctx.Repo.Owner.ID, repo.ID); err != nil {
ctx.Handle(500, "DeleteRepository", err) ctx.ServerError("DeleteRepository", err)
return return
} }
log.Trace("Repository deleted: %s/%s", ctx.Repo.Owner.Name, repo.Name) 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") ctx.Redirect(ctx.Repo.RepoLink + "/settings")
default: default:
ctx.Handle(404, "", nil) ctx.NotFound("", nil)
} }
} }
@ -335,7 +335,7 @@ func Collaboration(ctx *context.Context) {
users, err := ctx.Repo.Repository.GetCollaborators() users, err := ctx.Repo.Repository.GetCollaborators()
if err != nil { if err != nil {
ctx.Handle(500, "GetCollaborators", err) ctx.ServerError("GetCollaborators", err)
return return
} }
ctx.Data["Collaborators"] = users ctx.Data["Collaborators"] = users
@ -357,7 +357,7 @@ func CollaborationPost(ctx *context.Context) {
ctx.Flash.Error(ctx.Tr("form.user_not_exist")) ctx.Flash.Error(ctx.Tr("form.user_not_exist"))
ctx.Redirect(setting.AppSubURL + ctx.Req.URL.Path) ctx.Redirect(setting.AppSubURL + ctx.Req.URL.Path)
} else { } else {
ctx.Handle(500, "GetUserByName", err) ctx.ServerError("GetUserByName", err)
} }
return return
} }
@ -373,7 +373,7 @@ func CollaborationPost(ctx *context.Context) {
if ctx.Repo.Owner.IsOrganization() { if ctx.Repo.Owner.IsOrganization() {
isMember, err := ctx.Repo.Owner.IsOrgMember(u.ID) isMember, err := ctx.Repo.Owner.IsOrgMember(u.ID)
if err != nil { if err != nil {
ctx.Handle(500, "IsOrgMember", err) ctx.ServerError("IsOrgMember", err)
return return
} else if isMember { } else if isMember {
ctx.Flash.Info(ctx.Tr("repo.settings.user_is_org_member")) 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 { if err = ctx.Repo.Repository.AddCollaborator(u); err != nil {
ctx.Handle(500, "AddCollaborator", err) ctx.ServerError("AddCollaborator", err)
return return
} }
@ -422,9 +422,9 @@ func parseOwnerAndRepo(ctx *context.Context) (*models.User, *models.Repository)
owner, err := models.GetUserByName(ctx.Params(":username")) owner, err := models.GetUserByName(ctx.Params(":username"))
if err != nil { if err != nil {
if models.IsErrUserNotExist(err) { if models.IsErrUserNotExist(err) {
ctx.Handle(404, "GetUserByName", err) ctx.NotFound("GetUserByName", err)
} else { } else {
ctx.Handle(500, "GetUserByName", err) ctx.ServerError("GetUserByName", err)
} }
return nil, nil 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")) repo, err := models.GetRepositoryByName(owner.ID, ctx.Params(":reponame"))
if err != nil { if err != nil {
if models.IsErrRepoNotExist(err) { if models.IsErrRepoNotExist(err) {
ctx.Handle(404, "GetRepositoryByName", err) ctx.NotFound("GetRepositoryByName", err)
} else { } else {
ctx.Handle(500, "GetRepositoryByName", err) ctx.ServerError("GetRepositoryByName", err)
} }
return nil, nil return nil, nil
} }
@ -449,7 +449,7 @@ func GitHooks(ctx *context.Context) {
hooks, err := ctx.Repo.GitRepo.Hooks() hooks, err := ctx.Repo.GitRepo.Hooks()
if err != nil { if err != nil {
ctx.Handle(500, "Hooks", err) ctx.ServerError("Hooks", err)
return return
} }
ctx.Data["Hooks"] = hooks ctx.Data["Hooks"] = hooks
@ -466,9 +466,9 @@ func GitHooksEdit(ctx *context.Context) {
hook, err := ctx.Repo.GitRepo.GetHook(name) hook, err := ctx.Repo.GitRepo.GetHook(name)
if err != nil { if err != nil {
if err == git.ErrNotValidHook { if err == git.ErrNotValidHook {
ctx.Handle(404, "GetHook", err) ctx.NotFound("GetHook", err)
} else { } else {
ctx.Handle(500, "GetHook", err) ctx.ServerError("GetHook", err)
} }
return return
} }
@ -482,15 +482,15 @@ func GitHooksEditPost(ctx *context.Context) {
hook, err := ctx.Repo.GitRepo.GetHook(name) hook, err := ctx.Repo.GitRepo.GetHook(name)
if err != nil { if err != nil {
if err == git.ErrNotValidHook { if err == git.ErrNotValidHook {
ctx.Handle(404, "GetHook", err) ctx.NotFound("GetHook", err)
} else { } else {
ctx.Handle(500, "GetHook", err) ctx.ServerError("GetHook", err)
} }
return return
} }
hook.Content = ctx.Query("content") hook.Content = ctx.Query("content")
if err = hook.Update(); err != nil { if err = hook.Update(); err != nil {
ctx.Handle(500, "hook.Update", err) ctx.ServerError("hook.Update", err)
return return
} }
ctx.Redirect(ctx.Repo.RepoLink + "/settings/hooks/git") 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) keys, err := models.ListDeployKeys(ctx.Repo.Repository.ID)
if err != nil { if err != nil {
ctx.Handle(500, "ListDeployKeys", err) ctx.ServerError("ListDeployKeys", err)
return return
} }
ctx.Data["Deploykeys"] = keys ctx.Data["Deploykeys"] = keys
@ -519,7 +519,7 @@ func DeployKeysPost(ctx *context.Context, form auth.AddKeyForm) {
keys, err := models.ListDeployKeys(ctx.Repo.Repository.ID) keys, err := models.ListDeployKeys(ctx.Repo.Repository.ID)
if err != nil { if err != nil {
ctx.Handle(500, "ListDeployKeys", err) ctx.ServerError("ListDeployKeys", err)
return return
} }
ctx.Data["Deploykeys"] = keys ctx.Data["Deploykeys"] = keys
@ -555,7 +555,7 @@ func DeployKeysPost(ctx *context.Context, form auth.AddKeyForm) {
ctx.Data["Err_Title"] = true ctx.Data["Err_Title"] = true
ctx.RenderWithErr(ctx.Tr("repo.settings.key_name_used"), tplDeployKeys, &form) ctx.RenderWithErr(ctx.Tr("repo.settings.key_name_used"), tplDeployKeys, &form)
default: default:
ctx.Handle(500, "AddDeployKey", err) ctx.ServerError("AddDeployKey", err)
} }
return return
} }

View File

@ -24,7 +24,7 @@ func ProtectedBranch(ctx *context.Context) {
protectedBranches, err := ctx.Repo.Repository.GetProtectedBranches() protectedBranches, err := ctx.Repo.Repository.GetProtectedBranches()
if err != nil { if err != nil {
ctx.Handle(500, "GetProtectedBranches", err) ctx.ServerError("GetProtectedBranches", err)
return return
} }
ctx.Data["ProtectedBranches"] = protectedBranches ctx.Data["ProtectedBranches"] = protectedBranches
@ -71,12 +71,12 @@ func ProtectedBranchPost(ctx *context.Context) {
repo.DefaultBranch = branch repo.DefaultBranch = branch
if err := ctx.Repo.GitRepo.SetDefaultBranch(branch); err != nil { if err := ctx.Repo.GitRepo.SetDefaultBranch(branch); err != nil {
if !git.IsErrUnsupportedVersion(err) { if !git.IsErrUnsupportedVersion(err) {
ctx.Handle(500, "SetDefaultBranch", err) ctx.ServerError("SetDefaultBranch", err)
return return
} }
} }
if err := repo.UpdateDefaultBranch(); err != nil { if err := repo.UpdateDefaultBranch(); err != nil {
ctx.Handle(500, "SetDefaultBranch", err) ctx.ServerError("SetDefaultBranch", err)
return return
} }
} }
@ -86,7 +86,7 @@ func ProtectedBranchPost(ctx *context.Context) {
ctx.Flash.Success(ctx.Tr("repo.settings.update_settings_success")) ctx.Flash.Success(ctx.Tr("repo.settings.update_settings_success"))
ctx.Redirect(setting.AppSubURL + ctx.Req.URL.Path) ctx.Redirect(setting.AppSubURL + ctx.Req.URL.Path)
default: default:
ctx.Handle(404, "", nil) ctx.NotFound("", nil)
} }
} }
@ -94,7 +94,7 @@ func ProtectedBranchPost(ctx *context.Context) {
func SettingsProtectedBranch(c *context.Context) { func SettingsProtectedBranch(c *context.Context) {
branch := c.Params("*") branch := c.Params("*")
if !c.Repo.GitRepo.IsBranchExist(branch) { if !c.Repo.GitRepo.IsBranchExist(branch) {
c.NotFound() c.NotFound("IsBranchExist", nil)
return return
} }
@ -104,7 +104,7 @@ func SettingsProtectedBranch(c *context.Context) {
protectBranch, err := models.GetProtectedBranchBy(c.Repo.Repository.ID, branch) protectBranch, err := models.GetProtectedBranchBy(c.Repo.Repository.ID, branch)
if err != nil { if err != nil {
if !models.IsErrBranchNotExist(err) { if !models.IsErrBranchNotExist(err) {
c.Handle(500, "GetProtectBranchOfRepoByName", err) c.ServerError("GetProtectBranchOfRepoByName", err)
return return
} }
} }
@ -118,7 +118,7 @@ func SettingsProtectedBranch(c *context.Context) {
users, err := c.Repo.Repository.GetWriters() users, err := c.Repo.Repository.GetWriters()
if err != nil { if err != nil {
c.Handle(500, "Repo.Repository.GetWriters", err) c.ServerError("Repo.Repository.GetWriters", err)
return return
} }
c.Data["Users"] = users c.Data["Users"] = users
@ -127,7 +127,7 @@ func SettingsProtectedBranch(c *context.Context) {
if c.Repo.Owner.IsOrganization() { if c.Repo.Owner.IsOrganization() {
teams, err := c.Repo.Owner.TeamsWithAccessToRepo(c.Repo.Repository.ID, models.AccessModeWrite) teams, err := c.Repo.Owner.TeamsWithAccessToRepo(c.Repo.Repository.ID, models.AccessModeWrite)
if err != nil { if err != nil {
c.Handle(500, "Repo.Owner.TeamsWithAccessToRepo", err) c.ServerError("Repo.Owner.TeamsWithAccessToRepo", err)
return return
} }
c.Data["Teams"] = teams c.Data["Teams"] = teams
@ -142,14 +142,14 @@ func SettingsProtectedBranch(c *context.Context) {
func SettingsProtectedBranchPost(ctx *context.Context, f auth.ProtectBranchForm) { func SettingsProtectedBranchPost(ctx *context.Context, f auth.ProtectBranchForm) {
branch := ctx.Params("*") branch := ctx.Params("*")
if !ctx.Repo.GitRepo.IsBranchExist(branch) { if !ctx.Repo.GitRepo.IsBranchExist(branch) {
ctx.NotFound() ctx.NotFound("IsBranchExist", nil)
return return
} }
protectBranch, err := models.GetProtectedBranchBy(ctx.Repo.Repository.ID, branch) protectBranch, err := models.GetProtectedBranchBy(ctx.Repo.Repository.ID, branch)
if err != nil { if err != nil {
if !models.IsErrBranchNotExist(err) { if !models.IsErrBranchNotExist(err) {
ctx.Handle(500, "GetProtectBranchOfRepoByName", err) ctx.ServerError("GetProtectBranchOfRepoByName", err)
return return
} }
} }
@ -168,7 +168,7 @@ func SettingsProtectedBranchPost(ctx *context.Context, f auth.ProtectBranchForm)
whitelistTeams, _ := base.StringsToInt64s(strings.Split(f.WhitelistTeams, ",")) whitelistTeams, _ := base.StringsToInt64s(strings.Split(f.WhitelistTeams, ","))
err = models.UpdateProtectBranch(ctx.Repo.Repository, protectBranch, whitelistUsers, whitelistTeams) err = models.UpdateProtectBranch(ctx.Repo.Repository, protectBranch, whitelistUsers, whitelistTeams)
if err != nil { if err != nil {
ctx.Handle(500, "UpdateProtectBranch", err) ctx.ServerError("UpdateProtectBranch", err)
return return
} }
ctx.Flash.Success(ctx.Tr("repo.settings.update_protect_branch_success", branch)) 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 { } else {
if protectBranch != nil { if protectBranch != nil {
if err := ctx.Repo.Repository.DeleteProtectedBranch(protectBranch.ID); err != nil { if err := ctx.Repo.Repository.DeleteProtectedBranch(protectBranch.ID); err != nil {
ctx.Handle(500, "DeleteProtectedBranch", err) ctx.ServerError("DeleteProtectedBranch", err)
return return
} }
} }

View File

@ -44,14 +44,14 @@ func renderDirectory(ctx *context.Context, treeLink string) {
entries, err := tree.ListEntries() entries, err := tree.ListEntries()
if err != nil { if err != nil {
ctx.Handle(500, "ListEntries", err) ctx.ServerError("ListEntries", err)
return return
} }
entries.CustomSort(base.NaturalSortLess) entries.CustomSort(base.NaturalSortLess)
ctx.Data["Files"], err = entries.GetCommitsInfo(ctx.Repo.Commit, ctx.Repo.TreePath) ctx.Data["Files"], err = entries.GetCommitsInfo(ctx.Repo.Commit, ctx.Repo.TreePath)
if err != nil { if err != nil {
ctx.Handle(500, "GetCommitsInfo", err) ctx.ServerError("GetCommitsInfo", err)
return return
} }
@ -78,7 +78,7 @@ func renderDirectory(ctx *context.Context, treeLink string) {
dataRc, err := readmeFile.DataAsync() dataRc, err := readmeFile.DataAsync()
if err != nil { if err != nil {
ctx.Handle(500, "Data", err) ctx.ServerError("Data", err)
return return
} }
defer dataRc.Close() defer dataRc.Close()
@ -117,7 +117,7 @@ func renderDirectory(ctx *context.Context, treeLink string) {
if len(ctx.Repo.TreePath) > 0 { if len(ctx.Repo.TreePath) > 0 {
latestCommit, err = ctx.Repo.Commit.GetCommitByPath(ctx.Repo.TreePath) latestCommit, err = ctx.Repo.Commit.GetCommitByPath(ctx.Repo.TreePath)
if err != nil { if err != nil {
ctx.Handle(500, "GetCommitByPath", err) ctx.ServerError("GetCommitByPath", err)
return return
} }
} }
@ -145,7 +145,7 @@ func renderFile(ctx *context.Context, entry *git.TreeEntry, treeLink, rawLink st
blob := entry.Blob() blob := entry.Blob()
dataRc, err := blob.DataAsync() dataRc, err := blob.DataAsync()
if err != nil { if err != nil {
ctx.Handle(500, "DataAsync", err) ctx.ServerError("DataAsync", err)
return return
} }
defer dataRc.Close() 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) { 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()) items, err := getter(pager.Current())
if err != nil { if err != nil {
ctx.Handle(500, "getter", err) ctx.ServerError("getter", err)
return return
} }
ctx.Data["Cards"] = items ctx.Data["Cards"] = items
@ -392,13 +392,13 @@ func Forks(ctx *context.Context) {
forks, err := ctx.Repo.Repository.GetForks() forks, err := ctx.Repo.Repository.GetForks()
if err != nil { if err != nil {
ctx.Handle(500, "GetForks", err) ctx.ServerError("GetForks", err)
return return
} }
for _, fork := range forks { for _, fork := range forks {
if err = fork.GetOwner(); err != nil { if err = fork.GetOwner(); err != nil {
ctx.Handle(500, "GetOwner", err) ctx.ServerError("GetOwner", err)
return return
} }
} }

View File

@ -37,7 +37,7 @@ func Webhooks(ctx *context.Context) {
ws, err := models.GetWebhooksByRepoID(ctx.Repo.Repository.ID) ws, err := models.GetWebhooksByRepoID(ctx.Repo.Repository.ID)
if err != nil { if err != nil {
ctx.Handle(500, "GetWebhooksByRepoID", err) ctx.ServerError("GetWebhooksByRepoID", err)
return return
} }
ctx.Data["Webhooks"] = ws ctx.Data["Webhooks"] = ws
@ -76,7 +76,7 @@ func getOrgRepoCtx(ctx *context.Context) (*orgRepoCtx, error) {
func checkHookType(ctx *context.Context) string { func checkHookType(ctx *context.Context) string {
hookType := strings.ToLower(ctx.Params(":type")) hookType := strings.ToLower(ctx.Params(":type"))
if !com.IsSliceContainsStr(setting.Webhook.Types, hookType) { if !com.IsSliceContainsStr(setting.Webhook.Types, hookType) {
ctx.Handle(404, "checkHookType", nil) ctx.NotFound("checkHookType", nil)
return "" return ""
} }
return hookType return hookType
@ -91,7 +91,7 @@ func WebhooksNew(ctx *context.Context) {
orCtx, err := getOrgRepoCtx(ctx) orCtx, err := getOrgRepoCtx(ctx)
if err != nil { if err != nil {
ctx.Handle(500, "getOrgRepoCtx", err) ctx.ServerError("getOrgRepoCtx", err)
return return
} }
@ -136,7 +136,7 @@ func WebHooksNewPost(ctx *context.Context, form auth.NewWebhookForm) {
orCtx, err := getOrgRepoCtx(ctx) orCtx, err := getOrgRepoCtx(ctx)
if err != nil { if err != nil {
ctx.Handle(500, "getOrgRepoCtx", err) ctx.ServerError("getOrgRepoCtx", err)
return return
} }
ctx.Data["BaseLink"] = orCtx.Link ctx.Data["BaseLink"] = orCtx.Link
@ -162,10 +162,10 @@ func WebHooksNewPost(ctx *context.Context, form auth.NewWebhookForm) {
OrgID: orCtx.OrgID, OrgID: orCtx.OrgID,
} }
if err := w.UpdateEvent(); err != nil { if err := w.UpdateEvent(); err != nil {
ctx.Handle(500, "UpdateEvent", err) ctx.ServerError("UpdateEvent", err)
return return
} else if err := models.CreateWebhook(w); err != nil { } else if err := models.CreateWebhook(w); err != nil {
ctx.Handle(500, "CreateWebhook", err) ctx.ServerError("CreateWebhook", err)
return return
} }
@ -183,7 +183,7 @@ func GogsHooksNewPost(ctx *context.Context, form auth.NewGogshookForm) {
orCtx, err := getOrgRepoCtx(ctx) orCtx, err := getOrgRepoCtx(ctx)
if err != nil { if err != nil {
ctx.Handle(500, "getOrgRepoCtx", err) ctx.ServerError("getOrgRepoCtx", err)
return return
} }
ctx.Data["BaseLink"] = orCtx.Link ctx.Data["BaseLink"] = orCtx.Link
@ -209,10 +209,10 @@ func GogsHooksNewPost(ctx *context.Context, form auth.NewGogshookForm) {
OrgID: orCtx.OrgID, OrgID: orCtx.OrgID,
} }
if err := w.UpdateEvent(); err != nil { if err := w.UpdateEvent(); err != nil {
ctx.Handle(500, "UpdateEvent", err) ctx.ServerError("UpdateEvent", err)
return return
} else if err := models.CreateWebhook(w); err != nil { } else if err := models.CreateWebhook(w); err != nil {
ctx.Handle(500, "CreateWebhook", err) ctx.ServerError("CreateWebhook", err)
return return
} }
@ -229,7 +229,7 @@ func DiscordHooksNewPost(ctx *context.Context, form auth.NewDiscordHookForm) {
orCtx, err := getOrgRepoCtx(ctx) orCtx, err := getOrgRepoCtx(ctx)
if err != nil { if err != nil {
ctx.Handle(500, "getOrgRepoCtx", err) ctx.ServerError("getOrgRepoCtx", err)
return return
} }
@ -243,7 +243,7 @@ func DiscordHooksNewPost(ctx *context.Context, form auth.NewDiscordHookForm) {
IconURL: form.IconURL, IconURL: form.IconURL,
}) })
if err != nil { if err != nil {
ctx.Handle(500, "Marshal", err) ctx.ServerError("Marshal", err)
return return
} }
@ -258,10 +258,10 @@ func DiscordHooksNewPost(ctx *context.Context, form auth.NewDiscordHookForm) {
OrgID: orCtx.OrgID, OrgID: orCtx.OrgID,
} }
if err := w.UpdateEvent(); err != nil { if err := w.UpdateEvent(); err != nil {
ctx.Handle(500, "UpdateEvent", err) ctx.ServerError("UpdateEvent", err)
return return
} else if err := models.CreateWebhook(w); err != nil { } else if err := models.CreateWebhook(w); err != nil {
ctx.Handle(500, "CreateWebhook", err) ctx.ServerError("CreateWebhook", err)
return return
} }
@ -278,7 +278,7 @@ func DingtalkHooksNewPost(ctx *context.Context, form auth.NewDingtalkHookForm) {
orCtx, err := getOrgRepoCtx(ctx) orCtx, err := getOrgRepoCtx(ctx)
if err != nil { if err != nil {
ctx.Handle(500, "getOrgRepoCtx", err) ctx.ServerError("getOrgRepoCtx", err)
return return
} }
@ -298,10 +298,10 @@ func DingtalkHooksNewPost(ctx *context.Context, form auth.NewDingtalkHookForm) {
OrgID: orCtx.OrgID, OrgID: orCtx.OrgID,
} }
if err := w.UpdateEvent(); err != nil { if err := w.UpdateEvent(); err != nil {
ctx.Handle(500, "UpdateEvent", err) ctx.ServerError("UpdateEvent", err)
return return
} else if err := models.CreateWebhook(w); err != nil { } else if err := models.CreateWebhook(w); err != nil {
ctx.Handle(500, "CreateWebhook", err) ctx.ServerError("CreateWebhook", err)
return return
} }
@ -318,7 +318,7 @@ func SlackHooksNewPost(ctx *context.Context, form auth.NewSlackHookForm) {
orCtx, err := getOrgRepoCtx(ctx) orCtx, err := getOrgRepoCtx(ctx)
if err != nil { if err != nil {
ctx.Handle(500, "getOrgRepoCtx", err) ctx.ServerError("getOrgRepoCtx", err)
return return
} }
@ -334,7 +334,7 @@ func SlackHooksNewPost(ctx *context.Context, form auth.NewSlackHookForm) {
Color: form.Color, Color: form.Color,
}) })
if err != nil { if err != nil {
ctx.Handle(500, "Marshal", err) ctx.ServerError("Marshal", err)
return return
} }
@ -349,10 +349,10 @@ func SlackHooksNewPost(ctx *context.Context, form auth.NewSlackHookForm) {
OrgID: orCtx.OrgID, OrgID: orCtx.OrgID,
} }
if err := w.UpdateEvent(); err != nil { if err := w.UpdateEvent(); err != nil {
ctx.Handle(500, "UpdateEvent", err) ctx.ServerError("UpdateEvent", err)
return return
} else if err := models.CreateWebhook(w); err != nil { } else if err := models.CreateWebhook(w); err != nil {
ctx.Handle(500, "CreateWebhook", err) ctx.ServerError("CreateWebhook", err)
return return
} }
@ -365,7 +365,7 @@ func checkWebhook(ctx *context.Context) (*orgRepoCtx, *models.Webhook) {
orCtx, err := getOrgRepoCtx(ctx) orCtx, err := getOrgRepoCtx(ctx)
if err != nil { if err != nil {
ctx.Handle(500, "getOrgRepoCtx", err) ctx.ServerError("getOrgRepoCtx", err)
return nil, nil return nil, nil
} }
ctx.Data["BaseLink"] = orCtx.Link ctx.Data["BaseLink"] = orCtx.Link
@ -378,9 +378,9 @@ func checkWebhook(ctx *context.Context) (*orgRepoCtx, *models.Webhook) {
} }
if err != nil { if err != nil {
if models.IsErrWebhookNotExist(err) { if models.IsErrWebhookNotExist(err) {
ctx.Handle(404, "GetWebhookByID", nil) ctx.NotFound("GetWebhookByID", nil)
} else { } else {
ctx.Handle(500, "GetWebhookByID", err) ctx.ServerError("GetWebhookByID", err)
} }
return nil, nil return nil, nil
} }
@ -395,7 +395,7 @@ func checkWebhook(ctx *context.Context) (*orgRepoCtx, *models.Webhook) {
ctx.Data["History"], err = w.History(1) ctx.Data["History"], err = w.History(1)
if err != nil { if err != nil {
ctx.Handle(500, "History", err) ctx.ServerError("History", err)
} }
return orCtx, w return orCtx, w
} }
@ -443,10 +443,10 @@ func WebHooksEditPost(ctx *context.Context, form auth.NewWebhookForm) {
w.HookEvent = ParseHookEvent(form.WebhookForm) w.HookEvent = ParseHookEvent(form.WebhookForm)
w.IsActive = form.Active w.IsActive = form.Active
if err := w.UpdateEvent(); err != nil { if err := w.UpdateEvent(); err != nil {
ctx.Handle(500, "UpdateEvent", err) ctx.ServerError("UpdateEvent", err)
return return
} else if err := models.UpdateWebhook(w); err != nil { } else if err := models.UpdateWebhook(w); err != nil {
ctx.Handle(500, "WebHooksEditPost", err) ctx.ServerError("WebHooksEditPost", err)
return return
} }
@ -482,10 +482,10 @@ func GogsHooksEditPost(ctx *context.Context, form auth.NewGogshookForm) {
w.HookEvent = ParseHookEvent(form.WebhookForm) w.HookEvent = ParseHookEvent(form.WebhookForm)
w.IsActive = form.Active w.IsActive = form.Active
if err := w.UpdateEvent(); err != nil { if err := w.UpdateEvent(); err != nil {
ctx.Handle(500, "UpdateEvent", err) ctx.ServerError("UpdateEvent", err)
return return
} else if err := models.UpdateWebhook(w); err != nil { } else if err := models.UpdateWebhook(w); err != nil {
ctx.Handle(500, "GogsHooksEditPost", err) ctx.ServerError("GogsHooksEditPost", err)
return return
} }
@ -517,7 +517,7 @@ func SlackHooksEditPost(ctx *context.Context, form auth.NewSlackHookForm) {
Color: form.Color, Color: form.Color,
}) })
if err != nil { if err != nil {
ctx.Handle(500, "Marshal", err) ctx.ServerError("Marshal", err)
return return
} }
@ -526,10 +526,10 @@ func SlackHooksEditPost(ctx *context.Context, form auth.NewSlackHookForm) {
w.HookEvent = ParseHookEvent(form.WebhookForm) w.HookEvent = ParseHookEvent(form.WebhookForm)
w.IsActive = form.Active w.IsActive = form.Active
if err := w.UpdateEvent(); err != nil { if err := w.UpdateEvent(); err != nil {
ctx.Handle(500, "UpdateEvent", err) ctx.ServerError("UpdateEvent", err)
return return
} else if err := models.UpdateWebhook(w); err != nil { } else if err := models.UpdateWebhook(w); err != nil {
ctx.Handle(500, "UpdateWebhook", err) ctx.ServerError("UpdateWebhook", err)
return return
} }
@ -559,7 +559,7 @@ func DiscordHooksEditPost(ctx *context.Context, form auth.NewDiscordHookForm) {
IconURL: form.IconURL, IconURL: form.IconURL,
}) })
if err != nil { if err != nil {
ctx.Handle(500, "Marshal", err) ctx.ServerError("Marshal", err)
return return
} }
@ -568,10 +568,10 @@ func DiscordHooksEditPost(ctx *context.Context, form auth.NewDiscordHookForm) {
w.HookEvent = ParseHookEvent(form.WebhookForm) w.HookEvent = ParseHookEvent(form.WebhookForm)
w.IsActive = form.Active w.IsActive = form.Active
if err := w.UpdateEvent(); err != nil { if err := w.UpdateEvent(); err != nil {
ctx.Handle(500, "UpdateEvent", err) ctx.ServerError("UpdateEvent", err)
return return
} else if err := models.UpdateWebhook(w); err != nil { } else if err := models.UpdateWebhook(w); err != nil {
ctx.Handle(500, "UpdateWebhook", err) ctx.ServerError("UpdateWebhook", err)
return return
} }
@ -600,10 +600,10 @@ func DingtalkHooksEditPost(ctx *context.Context, form auth.NewDingtalkHookForm)
w.HookEvent = ParseHookEvent(form.WebhookForm) w.HookEvent = ParseHookEvent(form.WebhookForm)
w.IsActive = form.Active w.IsActive = form.Active
if err := w.UpdateEvent(); err != nil { if err := w.UpdateEvent(); err != nil {
ctx.Handle(500, "UpdateEvent", err) ctx.ServerError("UpdateEvent", err)
return return
} else if err := models.UpdateWebhook(w); err != nil { } else if err := models.UpdateWebhook(w); err != nil {
ctx.Handle(500, "UpdateWebhook", err) ctx.ServerError("UpdateWebhook", err)
return return
} }

View File

@ -32,7 +32,7 @@ const (
func MustEnableWiki(ctx *context.Context) { func MustEnableWiki(ctx *context.Context) {
if !ctx.Repo.Repository.UnitEnabled(models.UnitTypeWiki) && if !ctx.Repo.Repository.UnitEnabled(models.UnitTypeWiki) &&
!ctx.Repo.Repository.UnitEnabled(models.UnitTypeExternalWiki) { !ctx.Repo.Repository.UnitEnabled(models.UnitTypeExternalWiki) {
ctx.Handle(404, "MustEnableWiki", nil) ctx.NotFound("MustEnableWiki", nil)
return 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) { func findWikiRepoCommit(ctx *context.Context) (*git.Repository, *git.Commit, error) {
wikiRepo, err := git.OpenRepository(ctx.Repo.Repository.WikiPath()) wikiRepo, err := git.OpenRepository(ctx.Repo.Repository.WikiPath())
if err != nil { if err != nil {
ctx.Handle(500, "OpenRepository", err) ctx.ServerError("OpenRepository", err)
return nil, nil, err return nil, nil, err
} }
commit, err := wikiRepo.GetBranchCommit("master") commit, err := wikiRepo.GetBranchCommit("master")
if err != nil { if err != nil {
ctx.Handle(500, "GetBranchCommit", err) ctx.ServerError("GetBranchCommit", err)
return wikiRepo, nil, err return wikiRepo, nil, err
} }
return wikiRepo, commit, nil 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 { func wikiContentsByEntry(ctx *context.Context, entry *git.TreeEntry) []byte {
reader, err := entry.Blob().Data() reader, err := entry.Blob().Data()
if err != nil { if err != nil {
ctx.Handle(500, "Blob.Data", err) ctx.ServerError("Blob.Data", err)
return nil return nil
} }
content, err := ioutil.ReadAll(reader) content, err := ioutil.ReadAll(reader)
if err != nil { if err != nil {
ctx.Handle(500, "ReadAll", err) ctx.ServerError("ReadAll", err)
return nil return nil
} }
return content 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) { func wikiContentsByName(ctx *context.Context, commit *git.Commit, wikiName string) ([]byte, bool) {
entry, err := findEntryForFile(commit, models.WikiNameToFilename(wikiName)) entry, err := findEntryForFile(commit, models.WikiNameToFilename(wikiName))
if err != nil { if err != nil {
ctx.Handle(500, "findEntryForFile", err) ctx.ServerError("findEntryForFile", err)
return nil, false return nil, false
} else if entry == nil { } else if entry == nil {
return nil, false return nil, false
@ -118,7 +118,7 @@ func renderWikiPage(ctx *context.Context, isViewPage bool) (*git.Repository, *gi
if isViewPage { if isViewPage {
entries, err := commit.ListEntries() entries, err := commit.ListEntries()
if err != nil { if err != nil {
ctx.Handle(500, "ListEntries", err) ctx.ServerError("ListEntries", err)
return nil, nil return nil, nil
} }
pages := make([]PageMeta, 0, len(entries)) 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()) wikiName, err := models.WikiFilenameToName(entry.Name())
if err != nil { if err != nil {
ctx.Handle(500, "WikiFilenameToName", err) ctx.ServerError("WikiFilenameToName", err)
return nil, nil return nil, nil
} else if wikiName == "_Sidebar" || wikiName == "_Footer" { } else if wikiName == "_Sidebar" || wikiName == "_Footer" {
continue continue
@ -155,7 +155,7 @@ func renderWikiPage(ctx *context.Context, isViewPage bool) (*git.Repository, *gi
pageFilename := models.WikiNameToFilename(pageName) pageFilename := models.WikiNameToFilename(pageName)
var entry *git.TreeEntry var entry *git.TreeEntry
if entry, err = findEntryForFile(commit, pageFilename); err != nil { if entry, err = findEntryForFile(commit, pageFilename); err != nil {
ctx.Handle(500, "findEntryForFile", err) ctx.ServerError("findEntryForFile", err)
return nil, nil return nil, nil
} else if entry == nil { } else if entry == nil {
ctx.Redirect(ctx.Repo.RepoLink + "/wiki/_pages") ctx.Redirect(ctx.Repo.RepoLink + "/wiki/_pages")
@ -222,7 +222,7 @@ func Wiki(ctx *context.Context) {
// Get last change information. // Get last change information.
lastCommit, err := wikiRepo.GetCommitByPath(wikiPath) lastCommit, err := wikiRepo.GetCommitByPath(wikiPath)
if err != nil { if err != nil {
ctx.Handle(500, "GetCommitByPath", err) ctx.ServerError("GetCommitByPath", err)
return return
} }
ctx.Data["Author"] = lastCommit.Author ctx.Data["Author"] = lastCommit.Author
@ -247,7 +247,7 @@ func WikiPages(ctx *context.Context) {
entries, err := commit.ListEntries() entries, err := commit.ListEntries()
if err != nil { if err != nil {
ctx.Handle(500, "ListEntries", err) ctx.ServerError("ListEntries", err)
return return
} }
pages := make([]PageMeta, 0, len(entries)) pages := make([]PageMeta, 0, len(entries))
@ -257,12 +257,12 @@ func WikiPages(ctx *context.Context) {
} }
c, err := wikiRepo.GetCommitByPath(entry.Name()) c, err := wikiRepo.GetCommitByPath(entry.Name())
if err != nil { if err != nil {
ctx.Handle(500, "GetCommit", err) ctx.ServerError("GetCommit", err)
return return
} }
wikiName, err := models.WikiFilenameToName(entry.Name()) wikiName, err := models.WikiFilenameToName(entry.Name())
if err != nil { if err != nil {
ctx.Handle(500, "WikiFilenameToName", err) ctx.ServerError("WikiFilenameToName", err)
return return
} }
pages = append(pages, PageMeta{ pages = append(pages, PageMeta{
@ -294,15 +294,15 @@ func WikiRaw(ctx *context.Context) {
entry, err = findEntryForFile(commit, wikiPath) entry, err = findEntryForFile(commit, wikiPath)
} }
if err != nil { if err != nil {
ctx.Handle(500, "findFile", err) ctx.ServerError("findFile", err)
return return
} else if entry == nil { } else if entry == nil {
ctx.Handle(404, "findEntryForFile", nil) ctx.NotFound("findEntryForFile", nil)
return return
} }
if err = ServeBlob(ctx, entry.Blob()); err != nil { 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.Data["Err_Title"] = true
ctx.RenderWithErr(ctx.Tr("repo.wiki.page_already_exists"), tplWikiNew, &form) ctx.RenderWithErr(ctx.Tr("repo.wiki.page_already_exists"), tplWikiNew, &form)
} else { } else {
ctx.Handle(500, "AddWikiPage", err) ctx.ServerError("AddWikiPage", err)
} }
return return
} }
@ -381,7 +381,7 @@ func EditWikiPost(ctx *context.Context, form auth.NewWikiForm) {
newWikiName := models.NormalizeWikiName(form.Title) newWikiName := models.NormalizeWikiName(form.Title)
if err := ctx.Repo.Repository.EditWikiPage(ctx.User, oldWikiName, newWikiName, form.Content, form.Message); err != nil { 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 return
} }
@ -396,7 +396,7 @@ func DeleteWikiPagePost(ctx *context.Context) {
} }
if err := ctx.Repo.Repository.DeleteWikiPage(ctx.User, wikiName); err != nil { if err := ctx.Repo.Repository.DeleteWikiPage(ctx.User, wikiName); err != nil {
ctx.Handle(500, "DeleteWikiPage", err) ctx.ServerError("DeleteWikiPage", err)
return return
} }

View File

@ -312,25 +312,25 @@ func RegisterRoutes(m *macaron.Macaron) {
if models.IsErrAttachmentNotExist(err) { if models.IsErrAttachmentNotExist(err) {
ctx.Error(404) ctx.Error(404)
} else { } else {
ctx.Handle(500, "GetAttachmentByUUID", err) ctx.ServerError("GetAttachmentByUUID", err)
} }
return return
} }
fr, err := os.Open(attach.LocalPath()) fr, err := os.Open(attach.LocalPath())
if err != nil { if err != nil {
ctx.Handle(500, "Open", err) ctx.ServerError("Open", err)
return return
} }
defer fr.Close() defer fr.Close()
if err := attach.IncreaseDownloadCount(); err != nil { if err := attach.IncreaseDownloadCount(); err != nil {
ctx.Handle(500, "Update", err) ctx.ServerError("Update", err)
return return
} }
if err = repo.ServeData(ctx, attach.Name, fr); err != nil { if err = repo.ServeData(ctx, attach.Name, fr); err != nil {
ctx.Handle(500, "ServeData", err) ctx.ServerError("ServeData", err)
return return
} }
}) })
@ -353,10 +353,6 @@ func RegisterRoutes(m *macaron.Macaron) {
m.Group("", func() { m.Group("", func() {
m.Get("/create", org.Create) m.Get("/create", org.Create)
m.Post("/create", bindIgnErr(auth.CreateOrgForm{}), org.CreatePost) m.Post("/create", bindIgnErr(auth.CreateOrgForm{}), org.CreatePost)
}, func(ctx *context.Context) {
if !ctx.User.CanCreateOrganization() {
ctx.NotFound()
}
}) })
m.Group("/:org", func() { m.Group("/:org", func() {
@ -575,12 +571,12 @@ func RegisterRoutes(m *macaron.Macaron) {
var err error var err error
ctx.Repo.Commit, err = ctx.Repo.GitRepo.GetBranchCommit(ctx.Repo.Repository.DefaultBranch) ctx.Repo.Commit, err = ctx.Repo.GitRepo.GetBranchCommit(ctx.Repo.Repository.DefaultBranch)
if err != nil { if err != nil {
ctx.Handle(500, "GetBranchCommit", err) ctx.ServerError("GetBranchCommit", err)
return return
} }
ctx.Repo.CommitsCount, err = ctx.Repo.GetCommitsCount() ctx.Repo.CommitsCount, err = ctx.Repo.GetCommitsCount()
if err != nil { if err != nil {
ctx.Handle(500, "GetCommitsCount", err) ctx.ServerError("GetCommitsCount", err)
return return
} }
ctx.Data["CommitsCount"] = ctx.Repo.CommitsCount ctx.Data["CommitsCount"] = ctx.Repo.CommitsCount
@ -696,7 +692,7 @@ func RegisterRoutes(m *macaron.Macaron) {
m.Post("/:lid/unlock", lfs.UnLockHandler) m.Post("/:lid/unlock", lfs.UnLockHandler)
}, context.RepoAssignment()) }, context.RepoAssignment())
m.Any("/*", func(ctx *context.Context) { m.Any("/*", func(ctx *context.Context) {
ctx.Handle(404, "", nil) ctx.NotFound("", nil)
}) })
}, ignSignInAndCsrf) }, ignSignInAndCsrf)
m.Any("/*", ignSignInAndCsrf, repo.HTTP) m.Any("/*", ignSignInAndCsrf, repo.HTTP)
@ -725,7 +721,7 @@ func RegisterRoutes(m *macaron.Macaron) {
if setting.HasRobotsTxt { if setting.HasRobotsTxt {
ctx.ServeFileContent(path.Join(setting.CustomPath, "robots.txt")) ctx.ServeFileContent(path.Join(setting.CustomPath, "robots.txt"))
} else { } else {
ctx.Handle(404, "", nil) ctx.NotFound("", nil)
} }
}) })

View File

@ -81,7 +81,7 @@ func checkAutoLogin(ctx *context.Context) bool {
// Check auto-login. // Check auto-login.
isSucceed, err := AutoSignIn(ctx) isSucceed, err := AutoSignIn(ctx)
if err != nil { if err != nil {
ctx.Handle(500, "AutoSignIn", err) ctx.ServerError("AutoSignIn", err)
return true return true
} }
@ -116,7 +116,7 @@ func SignIn(ctx *context.Context) {
orderedOAuth2Names, oauth2Providers, err := models.GetActiveOAuth2Providers() orderedOAuth2Names, oauth2Providers, err := models.GetActiveOAuth2Providers()
if err != nil { if err != nil {
ctx.Handle(500, "UserSignIn", err) ctx.ServerError("UserSignIn", err)
return return
} }
ctx.Data["OrderedOAuth2Names"] = orderedOAuth2Names ctx.Data["OrderedOAuth2Names"] = orderedOAuth2Names
@ -135,7 +135,7 @@ func SignInPost(ctx *context.Context, form auth.SignInForm) {
orderedOAuth2Names, oauth2Providers, err := models.GetActiveOAuth2Providers() orderedOAuth2Names, oauth2Providers, err := models.GetActiveOAuth2Providers()
if err != nil { if err != nil {
ctx.Handle(500, "UserSignIn", err) ctx.ServerError("UserSignIn", err)
return return
} }
ctx.Data["OrderedOAuth2Names"] = orderedOAuth2Names 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) ctx.RenderWithErr(ctx.Tr("form.email_been_used"), tplSignIn, &form)
log.Info("Failed authentication attempt for %s from %s", form.UserName, ctx.RemoteAddr()) log.Info("Failed authentication attempt for %s from %s", form.UserName, ctx.RemoteAddr())
} else { } else {
ctx.Handle(500, "UserSignIn", err) ctx.ServerError("UserSignIn", err)
} }
return return
} }
@ -171,7 +171,7 @@ func SignInPost(ctx *context.Context, form auth.SignInForm) {
if models.IsErrTwoFactorNotEnrolled(err) { if models.IsErrTwoFactorNotEnrolled(err) {
handleSignIn(ctx, u, form.Remember) handleSignIn(ctx, u, form.Remember)
} else { } else {
ctx.Handle(500, "UserSignIn", err) ctx.ServerError("UserSignIn", err)
} }
return return
} }
@ -193,7 +193,7 @@ func TwoFactor(ctx *context.Context) {
// Ensure user is in a 2FA session. // Ensure user is in a 2FA session.
if ctx.Session.Get("twofaUid") == nil { 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 return
} }
@ -207,21 +207,21 @@ func TwoFactorPost(ctx *context.Context, form auth.TwoFactorAuthForm) {
// Ensure user is in a 2FA session. // Ensure user is in a 2FA session.
idSess := ctx.Session.Get("twofaUid") idSess := ctx.Session.Get("twofaUid")
if idSess == nil { if idSess == nil {
ctx.Handle(500, "UserSignIn", errors.New("not in 2FA session")) ctx.ServerError("UserSignIn", errors.New("not in 2FA session"))
return return
} }
id := idSess.(int64) id := idSess.(int64)
twofa, err := models.GetTwoFactorByUID(id) twofa, err := models.GetTwoFactorByUID(id)
if err != nil { if err != nil {
ctx.Handle(500, "UserSignIn", err) ctx.ServerError("UserSignIn", err)
return return
} }
// Validate the passcode with the stored TOTP secret. // Validate the passcode with the stored TOTP secret.
ok, err := twofa.ValidateTOTP(form.Passcode) ok, err := twofa.ValidateTOTP(form.Passcode)
if err != nil { if err != nil {
ctx.Handle(500, "UserSignIn", err) ctx.ServerError("UserSignIn", err)
return return
} }
@ -229,20 +229,20 @@ func TwoFactorPost(ctx *context.Context, form auth.TwoFactorAuthForm) {
remember := ctx.Session.Get("twofaRemember").(bool) remember := ctx.Session.Get("twofaRemember").(bool)
u, err := models.GetUserByID(id) u, err := models.GetUserByID(id)
if err != nil { if err != nil {
ctx.Handle(500, "UserSignIn", err) ctx.ServerError("UserSignIn", err)
return return
} }
if ctx.Session.Get("linkAccount") != nil { if ctx.Session.Get("linkAccount") != nil {
gothUser := ctx.Session.Get("linkAccountGothUser") gothUser := ctx.Session.Get("linkAccountGothUser")
if gothUser == nil { if gothUser == nil {
ctx.Handle(500, "UserSignIn", errors.New("not in LinkAccount session")) ctx.ServerError("UserSignIn", errors.New("not in LinkAccount session"))
return return
} }
err = models.LinkAccountToUser(u, gothUser.(goth.User)) err = models.LinkAccountToUser(u, gothUser.(goth.User))
if err != nil { if err != nil {
ctx.Handle(500, "UserSignIn", err) ctx.ServerError("UserSignIn", err)
return return
} }
} }
@ -265,7 +265,7 @@ func TwoFactorScratch(ctx *context.Context) {
// Ensure user is in a 2FA session. // Ensure user is in a 2FA session.
if ctx.Session.Get("twofaUid") == nil { 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 return
} }
@ -279,14 +279,14 @@ func TwoFactorScratchPost(ctx *context.Context, form auth.TwoFactorScratchAuthFo
// Ensure user is in a 2FA session. // Ensure user is in a 2FA session.
idSess := ctx.Session.Get("twofaUid") idSess := ctx.Session.Get("twofaUid")
if idSess == nil { if idSess == nil {
ctx.Handle(500, "UserSignIn", errors.New("not in 2FA session")) ctx.ServerError("UserSignIn", errors.New("not in 2FA session"))
return return
} }
id := idSess.(int64) id := idSess.(int64)
twofa, err := models.GetTwoFactorByUID(id) twofa, err := models.GetTwoFactorByUID(id)
if err != nil { if err != nil {
ctx.Handle(500, "UserSignIn", err) ctx.ServerError("UserSignIn", err)
return return
} }
@ -295,14 +295,14 @@ func TwoFactorScratchPost(ctx *context.Context, form auth.TwoFactorScratchAuthFo
// Invalidate the scratch token. // Invalidate the scratch token.
twofa.ScratchToken = "" twofa.ScratchToken = ""
if err = models.UpdateTwoFactor(twofa); err != nil { if err = models.UpdateTwoFactor(twofa); err != nil {
ctx.Handle(500, "UserSignIn", err) ctx.ServerError("UserSignIn", err)
return return
} }
remember := ctx.Session.Get("twofaRemember").(bool) remember := ctx.Session.Get("twofaRemember").(bool)
u, err := models.GetUserByID(id) u, err := models.GetUserByID(id)
if err != nil { if err != nil {
ctx.Handle(500, "UserSignIn", err) ctx.ServerError("UserSignIn", err)
return return
} }
@ -343,7 +343,7 @@ func handleSignInFull(ctx *context.Context, u *models.User, remember bool, obeyR
// Register last login // Register last login
u.SetLastLogin() u.SetLastLogin()
if err := models.UpdateUserCols(u, "last_login_unix"); err != nil { if err := models.UpdateUserCols(u, "last_login_unix"); err != nil {
ctx.Handle(500, "UpdateUserCols", err) ctx.ServerError("UpdateUserCols", err)
return return
} }
@ -366,7 +366,7 @@ func SignInOAuth(ctx *context.Context) {
loginSource, err := models.GetActiveOAuth2LoginSourceByName(provider) loginSource, err := models.GetActiveOAuth2LoginSourceByName(provider)
if err != nil { if err != nil {
ctx.Handle(500, "SignIn", err) ctx.ServerError("SignIn", err)
return return
} }
@ -380,7 +380,7 @@ func SignInOAuth(ctx *context.Context) {
err = oauth2.Auth(loginSource.Name, ctx.Req.Request, ctx.Resp) err = oauth2.Auth(loginSource.Name, ctx.Req.Request, ctx.Resp)
if err != nil { if err != nil {
ctx.Handle(500, "SignIn", err) ctx.ServerError("SignIn", err)
} }
// redirect is done in oauth2.Auth // redirect is done in oauth2.Auth
} }
@ -392,12 +392,12 @@ func SignInOAuthCallback(ctx *context.Context) {
// first look if the provider is still active // first look if the provider is still active
loginSource, err := models.GetActiveOAuth2LoginSourceByName(provider) loginSource, err := models.GetActiveOAuth2LoginSourceByName(provider)
if err != nil { if err != nil {
ctx.Handle(500, "SignIn", err) ctx.ServerError("SignIn", err)
return return
} }
if loginSource == nil { 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 return
} }
@ -408,7 +408,7 @@ func SignInOAuthCallback(ctx *context.Context) {
func handleOAuth2SignIn(u *models.User, gothUser goth.User, ctx *context.Context, err error) { func handleOAuth2SignIn(u *models.User, gothUser goth.User, ctx *context.Context, err error) {
if err != nil { if err != nil {
ctx.Handle(500, "UserSignIn", err) ctx.ServerError("UserSignIn", err)
return return
} }
@ -433,7 +433,7 @@ func handleOAuth2SignIn(u *models.User, gothUser goth.User, ctx *context.Context
// Register last login // Register last login
u.SetLastLogin() u.SetLastLogin()
if err := models.UpdateUserCols(u, "last_login_unix"); err != nil { if err := models.UpdateUserCols(u, "last_login_unix"); err != nil {
ctx.Handle(500, "UpdateUserCols", err) ctx.ServerError("UpdateUserCols", err)
return return
} }
@ -445,7 +445,7 @@ func handleOAuth2SignIn(u *models.User, gothUser goth.User, ctx *context.Context
ctx.Redirect(setting.AppSubURL + "/") ctx.Redirect(setting.AppSubURL + "/")
} else { } else {
ctx.Handle(500, "UserSignIn", err) ctx.ServerError("UserSignIn", err)
} }
return return
} }
@ -513,7 +513,7 @@ func LinkAccount(ctx *context.Context) {
gothUser := ctx.Session.Get("linkAccountGothUser") gothUser := ctx.Session.Get("linkAccountGothUser")
if gothUser == nil { if gothUser == nil {
ctx.Handle(500, "UserSignIn", errors.New("not in LinkAccount session")) ctx.ServerError("UserSignIn", errors.New("not in LinkAccount session"))
return return
} }
@ -538,7 +538,7 @@ func LinkAccountPostSignIn(ctx *context.Context, signInForm auth.SignInForm) {
gothUser := ctx.Session.Get("linkAccountGothUser") gothUser := ctx.Session.Get("linkAccountGothUser")
if gothUser == nil { if gothUser == nil {
ctx.Handle(500, "UserSignIn", errors.New("not in LinkAccount session")) ctx.ServerError("UserSignIn", errors.New("not in LinkAccount session"))
return return
} }
@ -552,7 +552,7 @@ func LinkAccountPostSignIn(ctx *context.Context, signInForm auth.SignInForm) {
if models.IsErrUserNotExist(err) { if models.IsErrUserNotExist(err) {
ctx.RenderWithErr(ctx.Tr("form.username_password_incorrect"), tplLinkAccount, &signInForm) ctx.RenderWithErr(ctx.Tr("form.username_password_incorrect"), tplLinkAccount, &signInForm)
} else { } else {
ctx.Handle(500, "UserLinkAccount", err) ctx.ServerError("UserLinkAccount", err)
} }
return return
} }
@ -564,12 +564,12 @@ func LinkAccountPostSignIn(ctx *context.Context, signInForm auth.SignInForm) {
if models.IsErrTwoFactorNotEnrolled(err) { if models.IsErrTwoFactorNotEnrolled(err) {
err = models.LinkAccountToUser(u, gothUser.(goth.User)) err = models.LinkAccountToUser(u, gothUser.(goth.User))
if err != nil { if err != nil {
ctx.Handle(500, "UserLinkAccount", err) ctx.ServerError("UserLinkAccount", err)
} else { } else {
handleSignIn(ctx, u, signInForm.Remember) handleSignIn(ctx, u, signInForm.Remember)
} }
} else { } else {
ctx.Handle(500, "UserLinkAccount", err) ctx.ServerError("UserLinkAccount", err)
} }
return return
} }
@ -597,7 +597,7 @@ func LinkAccountPostRegister(ctx *context.Context, cpt *captcha.Captcha, form au
gothUser := ctx.Session.Get("linkAccountGothUser") gothUser := ctx.Session.Get("linkAccountGothUser")
if gothUser == nil { if gothUser == nil {
ctx.Handle(500, "UserSignUp", errors.New("not in LinkAccount session")) ctx.ServerError("UserSignUp", errors.New("not in LinkAccount session"))
return return
} }
@ -630,7 +630,7 @@ func LinkAccountPostRegister(ctx *context.Context, cpt *captcha.Captcha, form au
loginSource, err := models.GetActiveOAuth2LoginSourceByName(gothUser.(goth.User).Provider) loginSource, err := models.GetActiveOAuth2LoginSourceByName(gothUser.(goth.User).Provider)
if err != nil { if err != nil {
ctx.Handle(500, "CreateUser", err) ctx.ServerError("CreateUser", err)
} }
u := &models.User{ u := &models.User{
@ -658,7 +658,7 @@ func LinkAccountPostRegister(ctx *context.Context, cpt *captcha.Captcha, form au
ctx.Data["Err_UserName"] = true ctx.Data["Err_UserName"] = true
ctx.RenderWithErr(ctx.Tr("user.form.name_pattern_not_allowed", err.(models.ErrNamePatternNotAllowed).Pattern), tplLinkAccount, &form) ctx.RenderWithErr(ctx.Tr("user.form.name_pattern_not_allowed", err.(models.ErrNamePatternNotAllowed).Pattern), tplLinkAccount, &form)
default: default:
ctx.Handle(500, "CreateUser", err) ctx.ServerError("CreateUser", err)
} }
return return
} }
@ -670,7 +670,7 @@ func LinkAccountPostRegister(ctx *context.Context, cpt *captcha.Captcha, form au
u.IsActive = true u.IsActive = true
u.SetLastLogin() u.SetLastLogin()
if err := models.UpdateUserCols(u, "is_admin", "is_active", "last_login_unix"); err != nil { if err := models.UpdateUserCols(u, "is_admin", "is_active", "last_login_unix"); err != nil {
ctx.Handle(500, "UpdateUser", err) ctx.ServerError("UpdateUser", err)
return return
} }
} }
@ -774,7 +774,7 @@ func SignUpPost(ctx *context.Context, cpt *captcha.Captcha, form auth.RegisterFo
ctx.Data["Err_UserName"] = true ctx.Data["Err_UserName"] = true
ctx.RenderWithErr(ctx.Tr("user.form.name_pattern_not_allowed", err.(models.ErrNamePatternNotAllowed).Pattern), tplSignUp, &form) ctx.RenderWithErr(ctx.Tr("user.form.name_pattern_not_allowed", err.(models.ErrNamePatternNotAllowed).Pattern), tplSignUp, &form)
default: default:
ctx.Handle(500, "CreateUser", err) ctx.ServerError("CreateUser", err)
} }
return return
} }
@ -786,7 +786,7 @@ func SignUpPost(ctx *context.Context, cpt *captcha.Captcha, form auth.RegisterFo
u.IsActive = true u.IsActive = true
u.SetLastLogin() u.SetLastLogin()
if err := models.UpdateUserCols(u, "is_admin", "is_active", "last_login_unix"); err != nil { if err := models.UpdateUserCols(u, "is_admin", "is_active", "last_login_unix"); err != nil {
ctx.Handle(500, "UpdateUser", err) ctx.ServerError("UpdateUser", err)
return return
} }
} }
@ -841,14 +841,14 @@ func Activate(ctx *context.Context) {
user.IsActive = true user.IsActive = true
var err error var err error
if user.Rands, err = models.GetUserSalt(); err != nil { if user.Rands, err = models.GetUserSalt(); err != nil {
ctx.Handle(500, "UpdateUser", err) ctx.ServerError("UpdateUser", err)
return return
} }
if err := models.UpdateUserCols(user, "is_active", "rands"); err != nil { if err := models.UpdateUserCols(user, "is_active", "rands"); err != nil {
if models.IsErrUserNotExist(err) { if models.IsErrUserNotExist(err) {
ctx.Error(404) ctx.Error(404)
} else { } else {
ctx.Handle(500, "UpdateUser", err) ctx.ServerError("UpdateUser", err)
} }
return return
} }
@ -873,7 +873,7 @@ func ActivateEmail(ctx *context.Context) {
// Verify code. // Verify code.
if email := models.VerifyActiveEmailCode(code, emailStr); email != nil { if email := models.VerifyActiveEmailCode(code, emailStr); email != nil {
if err := email.Activate(); err != nil { if err := email.Activate(); err != nil {
ctx.Handle(500, "ActivateEmail", err) ctx.ServerError("ActivateEmail", err)
} }
log.Trace("Email activated: %s", email.Email) 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") ctx.Data["Title"] = ctx.Tr("auth.forgot_password_title")
if setting.MailService == nil { if setting.MailService == nil {
ctx.Handle(403, "ForgotPasswdPost", nil) ctx.NotFound("ForgotPasswdPost", nil)
return return
} }
ctx.Data["IsResetRequest"] = true ctx.Data["IsResetRequest"] = true
@ -923,7 +923,7 @@ func ForgotPasswdPost(ctx *context.Context) {
return return
} }
ctx.Handle(500, "user.ResetPasswd(check existence)", err) ctx.ServerError("user.ResetPasswd(check existence)", err)
return return
} }
@ -987,16 +987,16 @@ func ResetPasswdPost(ctx *context.Context) {
u.Passwd = passwd u.Passwd = passwd
var err error var err error
if u.Rands, err = models.GetUserSalt(); err != nil { if u.Rands, err = models.GetUserSalt(); err != nil {
ctx.Handle(500, "UpdateUser", err) ctx.ServerError("UpdateUser", err)
return return
} }
if u.Salt, err = models.GetUserSalt(); err != nil { if u.Salt, err = models.GetUserSalt(); err != nil {
ctx.Handle(500, "UpdateUser", err) ctx.ServerError("UpdateUser", err)
return return
} }
u.HashPassword() u.HashPassword()
if err := models.UpdateUserCols(u, "passwd", "rands", "salt"); err != nil { if err := models.UpdateUserCols(u, "passwd", "rands", "salt"); err != nil {
ctx.Handle(500, "UpdateUser", err) ctx.ServerError("UpdateUser", err)
return return
} }

View File

@ -37,7 +37,7 @@ func SignInOpenID(ctx *context.Context) {
// Check auto-login. // Check auto-login.
isSucceed, err := AutoSignIn(ctx) isSucceed, err := AutoSignIn(ctx)
if err != nil { if err != nil {
ctx.Handle(500, "AutoSignIn", err) ctx.ServerError("AutoSignIn", err)
return return
} }
@ -276,7 +276,7 @@ func ConnectOpenIDPost(ctx *context.Context, form auth.ConnectOpenIDForm) {
if models.IsErrUserNotExist(err) { if models.IsErrUserNotExist(err) {
ctx.RenderWithErr(ctx.Tr("form.username_password_incorrect"), tplConnectOID, &form) ctx.RenderWithErr(ctx.Tr("form.username_password_incorrect"), tplConnectOID, &form)
} else { } else {
ctx.Handle(500, "ConnectOpenIDPost", err) ctx.ServerError("ConnectOpenIDPost", err)
} }
return return
} }
@ -288,7 +288,7 @@ func ConnectOpenIDPost(ctx *context.Context, form auth.ConnectOpenIDForm) {
ctx.RenderWithErr(ctx.Tr("form.openid_been_used", oid), tplConnectOID, &form) ctx.RenderWithErr(ctx.Tr("form.openid_been_used", oid), tplConnectOID, &form)
return return
} }
ctx.Handle(500, "AddUserOpenID", err) ctx.ServerError("AddUserOpenID", err)
return return
} }
@ -376,7 +376,7 @@ func RegisterOpenIDPost(ctx *context.Context, cpt *captcha.Captcha, form auth.Si
ctx.Data["Err_UserName"] = true ctx.Data["Err_UserName"] = true
ctx.RenderWithErr(ctx.Tr("user.form.name_pattern_not_allowed", err.(models.ErrNamePatternNotAllowed).Pattern), tplSignUpOID, &form) ctx.RenderWithErr(ctx.Tr("user.form.name_pattern_not_allowed", err.(models.ErrNamePatternNotAllowed).Pattern), tplSignUpOID, &form)
default: default:
ctx.Handle(500, "CreateUser", err) ctx.ServerError("CreateUser", err)
} }
return 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) ctx.RenderWithErr(ctx.Tr("form.openid_been_used", oid), tplSignUpOID, &form)
return return
} }
ctx.Handle(500, "AddUserOpenID", err) ctx.ServerError("AddUserOpenID", err)
return return
} }
@ -399,7 +399,7 @@ func RegisterOpenIDPost(ctx *context.Context, cpt *captcha.Captcha, form auth.Si
u.IsActive = true u.IsActive = true
u.SetLastLogin() u.SetLastLogin()
if err := models.UpdateUserCols(u, "is_admin", "is_active", "last_login_unix"); err != nil { if err := models.UpdateUserCols(u, "is_admin", "is_active", "last_login_unix"); err != nil {
ctx.Handle(500, "UpdateUser", err) ctx.ServerError("UpdateUser", err)
return return
} }
} }

View File

@ -35,9 +35,9 @@ func getDashboardContextUser(ctx *context.Context) *models.User {
org, err := models.GetUserByName(orgName) org, err := models.GetUserByName(orgName)
if err != nil { if err != nil {
if models.IsErrUserNotExist(err) { if models.IsErrUserNotExist(err) {
ctx.Handle(404, "GetUserByName", err) ctx.NotFound("GetUserByName", err)
} else { } else {
ctx.Handle(500, "GetUserByName", err) ctx.ServerError("GetUserByName", err)
} }
return nil return nil
} }
@ -46,7 +46,7 @@ func getDashboardContextUser(ctx *context.Context) *models.User {
ctx.Data["ContextUser"] = ctxUser ctx.Data["ContextUser"] = ctxUser
if err := ctx.User.GetOrganizations(true); err != nil { if err := ctx.User.GetOrganizations(true); err != nil {
ctx.Handle(500, "GetOrganizations", err) ctx.ServerError("GetOrganizations", err)
return nil return nil
} }
ctx.Data["Orgs"] = ctx.User.Orgs 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) { func retrieveFeeds(ctx *context.Context, options models.GetFeedsOptions) {
actions, err := models.GetFeeds(options) actions, err := models.GetFeeds(options)
if err != nil { if err != nil {
ctx.Handle(500, "GetFeeds", err) ctx.ServerError("GetFeeds", err)
return return
} }
@ -76,7 +76,7 @@ func retrieveFeeds(ctx *context.Context, options models.GetFeedsOptions) {
if models.IsErrUserNotExist(err) { if models.IsErrUserNotExist(err) {
continue continue
} }
ctx.Handle(500, "GetUserByID", err) ctx.ServerError("GetUserByID", err)
return return
} }
userCache[act.ActUserID] = u userCache[act.ActUserID] = u
@ -90,7 +90,7 @@ func retrieveFeeds(ctx *context.Context, options models.GetFeedsOptions) {
if models.IsErrRepoNotExist(err) { if models.IsErrRepoNotExist(err) {
continue continue
} }
ctx.Handle(500, "GetRepositoryByID", err) ctx.ServerError("GetRepositoryByID", err)
return return
} }
} }
@ -103,7 +103,7 @@ func retrieveFeeds(ctx *context.Context, options models.GetFeedsOptions) {
if models.IsErrUserNotExist(err) { if models.IsErrUserNotExist(err) {
continue continue
} }
ctx.Handle(500, "GetUserByID", err) ctx.ServerError("GetUserByID", err)
return return
} }
} }
@ -129,26 +129,26 @@ func Dashboard(ctx *context.Context) {
if ctxUser.IsOrganization() { if ctxUser.IsOrganization() {
env, err := ctxUser.AccessibleReposEnv(ctx.User.ID) env, err := ctxUser.AccessibleReposEnv(ctx.User.ID)
if err != nil { if err != nil {
ctx.Handle(500, "AccessibleReposEnv", err) ctx.ServerError("AccessibleReposEnv", err)
return return
} }
mirrors, err = env.MirrorRepos() mirrors, err = env.MirrorRepos()
if err != nil { if err != nil {
ctx.Handle(500, "env.MirrorRepos", err) ctx.ServerError("env.MirrorRepos", err)
return return
} }
} else { } else {
mirrors, err = ctxUser.GetMirrorRepositories() mirrors, err = ctxUser.GetMirrorRepositories()
if err != nil { if err != nil {
ctx.Handle(500, "GetMirrorRepositories", err) ctx.ServerError("GetMirrorRepositories", err)
return return
} }
} }
ctx.Data["MaxShowRepoNum"] = setting.UI.User.RepoPagingNum ctx.Data["MaxShowRepoNum"] = setting.UI.User.RepoPagingNum
if err := models.MirrorRepositoryList(mirrors).LoadAttributes(); err != nil { if err := models.MirrorRepositoryList(mirrors).LoadAttributes(); err != nil {
ctx.Handle(500, "MirrorRepositoryList.LoadAttributes", err) ctx.ServerError("MirrorRepositoryList.LoadAttributes", err)
return return
} }
ctx.Data["MirrorCount"] = len(mirrors) ctx.Data["MirrorCount"] = len(mirrors)
@ -217,18 +217,18 @@ func Issues(ctx *context.Context) {
if ctxUser.IsOrganization() { if ctxUser.IsOrganization() {
env, err := ctxUser.AccessibleReposEnv(ctx.User.ID) env, err := ctxUser.AccessibleReposEnv(ctx.User.ID)
if err != nil { if err != nil {
ctx.Handle(500, "AccessibleReposEnv", err) ctx.ServerError("AccessibleReposEnv", err)
return return
} }
userRepoIDs, err = env.RepoIDs(1, ctxUser.NumRepos) userRepoIDs, err = env.RepoIDs(1, ctxUser.NumRepos)
if err != nil { if err != nil {
ctx.Handle(500, "env.RepoIDs", err) ctx.ServerError("env.RepoIDs", err)
return return
} }
} else { } else {
userRepoIDs, err = ctxUser.GetAccessRepoIDs() userRepoIDs, err = ctxUser.GetAccessRepoIDs()
if err != nil { if err != nil {
ctx.Handle(500, "ctxUser.GetAccessRepoIDs", err) ctx.ServerError("ctxUser.GetAccessRepoIDs", err)
return return
} }
} }
@ -266,7 +266,7 @@ func Issues(ctx *context.Context) {
counts, err := models.CountIssuesByRepo(opts) counts, err := models.CountIssuesByRepo(opts)
if err != nil { if err != nil {
ctx.Handle(500, "CountIssuesByRepo", err) ctx.ServerError("CountIssuesByRepo", err)
return return
} }
@ -274,7 +274,7 @@ func Issues(ctx *context.Context) {
opts.PageSize = setting.UI.IssuePagingNum opts.PageSize = setting.UI.IssuePagingNum
issues, err := models.Issues(opts) issues, err := models.Issues(opts)
if err != nil { if err != nil {
ctx.Handle(500, "Issues", err) ctx.ServerError("Issues", err)
return return
} }
@ -282,7 +282,7 @@ func Issues(ctx *context.Context) {
for repoID := range counts { for repoID := range counts {
repo, err := models.GetRepositoryByID(repoID) repo, err := models.GetRepositoryByID(repoID)
if err != nil { if err != nil {
ctx.Handle(500, "GetRepositoryByID", err) ctx.ServerError("GetRepositoryByID", err)
return return
} }
showReposMap[repoID] = repo showReposMap[repoID] = repo
@ -292,7 +292,7 @@ func Issues(ctx *context.Context) {
if _, ok := showReposMap[repoID]; !ok { if _, ok := showReposMap[repoID]; !ok {
repo, err := models.GetRepositoryByID(repoID) repo, err := models.GetRepositoryByID(repoID)
if err != nil { if err != nil {
ctx.Handle(500, "GetRepositoryByID", fmt.Errorf("[%d]%v", repoID, err)) ctx.ServerError("GetRepositoryByID", fmt.Errorf("[%d]%v", repoID, err))
return return
} }
showReposMap[repoID] = repo showReposMap[repoID] = repo
@ -310,7 +310,7 @@ func Issues(ctx *context.Context) {
showRepos := models.RepositoryListOfMap(showReposMap) showRepos := models.RepositoryListOfMap(showReposMap)
sort.Sort(showRepos) sort.Sort(showRepos)
if err = showRepos.LoadAttributes(); err != nil { if err = showRepos.LoadAttributes(); err != nil {
ctx.Handle(500, "LoadAttributes", err) ctx.ServerError("LoadAttributes", err)
return return
} }
@ -327,7 +327,7 @@ func Issues(ctx *context.Context) {
IsClosed: isShowClosed, IsClosed: isShowClosed,
}) })
if err != nil { if err != nil {
ctx.Handle(500, "GetUserIssueStats", err) ctx.ServerError("GetUserIssueStats", err)
return return
} }
@ -361,7 +361,7 @@ func Issues(ctx *context.Context) {
func ShowSSHKeys(ctx *context.Context, uid int64) { func ShowSSHKeys(ctx *context.Context, uid int64) {
keys, err := models.ListPublicKeys(uid) keys, err := models.ListPublicKeys(uid)
if err != nil { if err != nil {
ctx.Handle(500, "ListPublicKeys", err) ctx.ServerError("ListPublicKeys", err)
return return
} }
@ -396,17 +396,17 @@ func showOrgProfile(ctx *context.Context) {
if ctx.IsSigned && !ctx.User.IsAdmin { if ctx.IsSigned && !ctx.User.IsAdmin {
env, err := org.AccessibleReposEnv(ctx.User.ID) env, err := org.AccessibleReposEnv(ctx.User.ID)
if err != nil { if err != nil {
ctx.Handle(500, "AccessibleReposEnv", err) ctx.ServerError("AccessibleReposEnv", err)
return return
} }
repos, err = env.Repos(page, setting.UI.User.RepoPagingNum) repos, err = env.Repos(page, setting.UI.User.RepoPagingNum)
if err != nil { if err != nil {
ctx.Handle(500, "env.Repos", err) ctx.ServerError("env.Repos", err)
return return
} }
count, err = env.CountRepos() count, err = env.CountRepos()
if err != nil { if err != nil {
ctx.Handle(500, "env.CountRepos", err) ctx.ServerError("env.CountRepos", err)
return return
} }
ctx.Data["Repos"] = repos ctx.Data["Repos"] = repos
@ -414,7 +414,7 @@ func showOrgProfile(ctx *context.Context) {
showPrivate := ctx.IsSigned && ctx.User.IsAdmin showPrivate := ctx.IsSigned && ctx.User.IsAdmin
repos, err = models.GetUserRepositories(org.ID, showPrivate, page, setting.UI.User.RepoPagingNum, "") repos, err = models.GetUserRepositories(org.ID, showPrivate, page, setting.UI.User.RepoPagingNum, "")
if err != nil { if err != nil {
ctx.Handle(500, "GetRepositories", err) ctx.ServerError("GetRepositories", err)
return return
} }
ctx.Data["Repos"] = repos 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) ctx.Data["Page"] = paginater.New(int(count), setting.UI.User.RepoPagingNum, page, 5)
if err := org.GetMembers(); err != nil { if err := org.GetMembers(); err != nil {
ctx.Handle(500, "GetMembers", err) ctx.ServerError("GetMembers", err)
return return
} }
ctx.Data["Members"] = org.Members ctx.Data["Members"] = org.Members
@ -438,9 +438,9 @@ func Email2User(ctx *context.Context) {
u, err := models.GetUserByEmail(ctx.Query("email")) u, err := models.GetUserByEmail(ctx.Query("email"))
if err != nil { if err != nil {
if models.IsErrUserNotExist(err) { if models.IsErrUserNotExist(err) {
ctx.Handle(404, "GetUserByEmail", err) ctx.NotFound("GetUserByEmail", err)
} else { } else {
ctx.Handle(500, "GetUserByEmail", err) ctx.ServerError("GetUserByEmail", err)
} }
return return
} }

View File

@ -30,7 +30,7 @@ func GetNotificationCount(c *context.Context) {
count, err := models.GetNotificationCount(c.User, models.NotificationStatusUnread) count, err := models.GetNotificationCount(c.User, models.NotificationStatusUnread)
if err != nil { if err != nil {
c.Handle(500, "GetNotificationCount", err) c.ServerError("GetNotificationCount", err)
return return
} }
@ -62,13 +62,13 @@ func Notifications(c *context.Context) {
statuses := []models.NotificationStatus{status, models.NotificationStatusPinned} statuses := []models.NotificationStatus{status, models.NotificationStatusPinned}
notifications, err := models.NotificationsForUser(c.User, statuses, page, perPage) notifications, err := models.NotificationsForUser(c.User, statuses, page, perPage)
if err != nil { if err != nil {
c.Handle(500, "ErrNotificationsForUser", err) c.ServerError("ErrNotificationsForUser", err)
return return
} }
total, err := models.GetNotificationCount(c.User, status) total, err := models.GetNotificationCount(c.User, status)
if err != nil { if err != nil {
c.Handle(500, "ErrGetNotificationCount", err) c.ServerError("ErrGetNotificationCount", err)
return return
} }
@ -100,12 +100,12 @@ func NotificationStatusPost(c *context.Context) {
case "pinned": case "pinned":
status = models.NotificationStatusPinned status = models.NotificationStatusPinned
default: default:
c.Handle(500, "InvalidNotificationStatus", errors.New("Invalid notification status")) c.ServerError("InvalidNotificationStatus", errors.New("Invalid notification status"))
return return
} }
if err := models.SetNotificationStatus(notificationID, c.User, status); err != nil { if err := models.SetNotificationStatus(notificationID, c.User, status); err != nil {
c.Handle(500, "SetNotificationStatus", err) c.ServerError("SetNotificationStatus", err)
return return
} }
@ -117,7 +117,7 @@ func NotificationStatusPost(c *context.Context) {
func NotificationPurgePost(c *context.Context) { func NotificationPurgePost(c *context.Context) {
err := models.UpdateNotificationStatuses(c.User, models.NotificationStatusUnread, models.NotificationStatusRead) err := models.UpdateNotificationStatuses(c.User, models.NotificationStatusUnread, models.NotificationStatusRead)
if err != nil { if err != nil {
c.Handle(500, "ErrUpdateNotificationStatuses", err) c.ServerError("ErrUpdateNotificationStatuses", err)
return return
} }

View File

@ -29,9 +29,9 @@ func GetUserByName(ctx *context.Context, name string) *models.User {
user, err := models.GetUserByName(name) user, err := models.GetUserByName(name)
if err != nil { if err != nil {
if models.IsErrUserNotExist(err) { if models.IsErrUserNotExist(err) {
ctx.Handle(404, "GetUserByName", nil) ctx.NotFound("GetUserByName", nil)
} else { } else {
ctx.Handle(500, "GetUserByName", err) ctx.ServerError("GetUserByName", err)
} }
return nil return nil
} }
@ -79,7 +79,7 @@ func Profile(ctx *context.Context) {
// Show OpenID URIs // Show OpenID URIs
openIDs, err := models.GetUserOpenIDs(ctxUser.ID) openIDs, err := models.GetUserOpenIDs(ctxUser.ID)
if err != nil { if err != nil {
ctx.Handle(500, "GetUserOpenIDs", err) ctx.ServerError("GetUserOpenIDs", err)
return return
} }
@ -91,7 +91,7 @@ func Profile(ctx *context.Context) {
orgs, err := models.GetOrgsByUserID(ctxUser.ID, showPrivate) orgs, err := models.GetOrgsByUserID(ctxUser.ID, showPrivate)
if err != nil { if err != nil {
ctx.Handle(500, "GetOrgsByUserIDDesc", err) ctx.ServerError("GetOrgsByUserIDDesc", err)
return return
} }
@ -147,13 +147,13 @@ func Profile(ctx *context.Context) {
if len(keyword) == 0 { if len(keyword) == 0 {
repos, err = ctxUser.GetStarredRepos(showPrivate, page, setting.UI.User.RepoPagingNum, orderBy.String()) repos, err = ctxUser.GetStarredRepos(showPrivate, page, setting.UI.User.RepoPagingNum, orderBy.String())
if err != nil { if err != nil {
ctx.Handle(500, "GetStarredRepos", err) ctx.ServerError("GetStarredRepos", err)
return return
} }
count, err = ctxUser.GetStarredRepoCount(showPrivate) count, err = ctxUser.GetStarredRepoCount(showPrivate)
if err != nil { if err != nil {
ctx.Handle(500, "GetStarredRepoCount", err) ctx.ServerError("GetStarredRepoCount", err)
return return
} }
} else { } else {
@ -168,7 +168,7 @@ func Profile(ctx *context.Context) {
Collaborate: util.OptionalBoolFalse, Collaborate: util.OptionalBoolFalse,
}) })
if err != nil { if err != nil {
ctx.Handle(500, "SearchRepositoryByName", err) ctx.ServerError("SearchRepositoryByName", err)
return return
} }
} }
@ -181,7 +181,7 @@ func Profile(ctx *context.Context) {
var total int var total int
repos, err = models.GetUserRepositories(ctxUser.ID, showPrivate, page, setting.UI.User.RepoPagingNum, orderBy.String()) repos, err = models.GetUserRepositories(ctxUser.ID, showPrivate, page, setting.UI.User.RepoPagingNum, orderBy.String())
if err != nil { if err != nil {
ctx.Handle(500, "GetRepositories", err) ctx.ServerError("GetRepositories", err)
return return
} }
ctx.Data["Repos"] = repos ctx.Data["Repos"] = repos
@ -191,7 +191,7 @@ func Profile(ctx *context.Context) {
} else { } else {
count, err := models.GetPublicRepositoryCount(ctxUser) count, err := models.GetPublicRepositoryCount(ctxUser)
if err != nil { if err != nil {
ctx.Handle(500, "GetPublicRepositoryCount", err) ctx.ServerError("GetPublicRepositoryCount", err)
return return
} }
total = int(count) total = int(count)
@ -210,7 +210,7 @@ func Profile(ctx *context.Context) {
PageSize: setting.UI.User.RepoPagingNum, PageSize: setting.UI.User.RepoPagingNum,
}) })
if err != nil { if err != nil {
ctx.Handle(500, "SearchRepositoryByName", err) ctx.ServerError("SearchRepositoryByName", err)
return return
} }
@ -267,7 +267,7 @@ func Action(ctx *context.Context) {
} }
if err != nil { 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 return
} }

View File

@ -73,7 +73,7 @@ func handleUsernameChange(ctx *context.Context, newName string) {
ctx.Flash.Error(ctx.Tr("user.newName_pattern_not_allowed")) ctx.Flash.Error(ctx.Tr("user.newName_pattern_not_allowed"))
ctx.Redirect(setting.AppSubURL + "/user/settings") ctx.Redirect(setting.AppSubURL + "/user/settings")
default: default:
ctx.Handle(500, "ChangeUserName", err) ctx.ServerError("ChangeUserName", err)
} }
return return
} }
@ -111,7 +111,7 @@ func SettingsPost(ctx *context.Context, form auth.UpdateProfileForm) {
ctx.Redirect(setting.AppSubURL + "/user/settings") ctx.Redirect(setting.AppSubURL + "/user/settings")
return return
} }
ctx.Handle(500, "UpdateUser", err) ctx.ServerError("UpdateUser", err)
return return
} }
@ -202,7 +202,7 @@ func SettingsSecurity(ctx *context.Context) {
if models.IsErrTwoFactorNotEnrolled(err) { if models.IsErrTwoFactorNotEnrolled(err) {
enrolled = false enrolled = false
} else { } else {
ctx.Handle(500, "SettingsTwoFactor", err) ctx.ServerError("SettingsTwoFactor", err)
return return
} }
} }
@ -232,12 +232,12 @@ func SettingsSecurityPost(ctx *context.Context, form auth.ChangePasswordForm) {
ctx.User.Passwd = form.Password ctx.User.Passwd = form.Password
var err error var err error
if ctx.User.Salt, err = models.GetUserSalt(); err != nil { if ctx.User.Salt, err = models.GetUserSalt(); err != nil {
ctx.Handle(500, "UpdateUser", err) ctx.ServerError("UpdateUser", err)
return return
} }
ctx.User.HashPassword() ctx.User.HashPassword()
if err := models.UpdateUserCols(ctx.User, "salt", "passwd"); err != nil { if err := models.UpdateUserCols(ctx.User, "salt", "passwd"); err != nil {
ctx.Handle(500, "UpdateUser", err) ctx.ServerError("UpdateUser", err)
return return
} }
log.Trace("User password updated: %s", ctx.User.Name) 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) emails, err := models.GetEmailAddresses(ctx.User.ID)
if err != nil { if err != nil {
ctx.Handle(500, "GetEmailAddresses", err) ctx.ServerError("GetEmailAddresses", err)
return return
} }
ctx.Data["Emails"] = emails ctx.Data["Emails"] = emails
@ -270,7 +270,7 @@ func SettingsEmailPost(ctx *context.Context, form auth.AddEmailForm) {
// Make emailaddress primary. // Make emailaddress primary.
if ctx.Query("_method") == "PRIMARY" { if ctx.Query("_method") == "PRIMARY" {
if err := models.MakeEmailPrimary(&models.EmailAddress{ID: ctx.QueryInt64("id")}); err != nil { if err := models.MakeEmailPrimary(&models.EmailAddress{ID: ctx.QueryInt64("id")}); err != nil {
ctx.Handle(500, "MakeEmailPrimary", err) ctx.ServerError("MakeEmailPrimary", err)
return return
} }
@ -282,7 +282,7 @@ func SettingsEmailPost(ctx *context.Context, form auth.AddEmailForm) {
// Add Email address. // Add Email address.
emails, err := models.GetEmailAddresses(ctx.User.ID) emails, err := models.GetEmailAddresses(ctx.User.ID)
if err != nil { if err != nil {
ctx.Handle(500, "GetEmailAddresses", err) ctx.ServerError("GetEmailAddresses", err)
return return
} }
ctx.Data["Emails"] = emails 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) ctx.RenderWithErr(ctx.Tr("form.email_been_used"), tplSettingsEmails, &form)
return return
} }
ctx.Handle(500, "AddEmailAddress", err) ctx.ServerError("AddEmailAddress", err)
return return
} }
@ -325,7 +325,7 @@ func SettingsEmailPost(ctx *context.Context, form auth.AddEmailForm) {
// DeleteEmail response for delete user's email // DeleteEmail response for delete user's email
func DeleteEmail(ctx *context.Context) { func DeleteEmail(ctx *context.Context) {
if err := models.DeleteEmailAddress(&models.EmailAddress{ID: ctx.QueryInt64("id"), UID: ctx.User.ID}); err != nil { 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 return
} }
log.Trace("Email address deleted: %s", ctx.User.Name) 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) keys, err := models.ListPublicKeys(ctx.User.ID)
if err != nil { if err != nil {
ctx.Handle(500, "ListPublicKeys", err) ctx.ServerError("ListPublicKeys", err)
return return
} }
ctx.Data["Keys"] = keys ctx.Data["Keys"] = keys
gpgkeys, err := models.ListGPGKeys(ctx.User.ID) gpgkeys, err := models.ListGPGKeys(ctx.User.ID)
if err != nil { if err != nil {
ctx.Handle(500, "ListGPGKeys", err) ctx.ServerError("ListGPGKeys", err)
return return
} }
ctx.Data["GPGKeys"] = gpgkeys ctx.Data["GPGKeys"] = gpgkeys
@ -366,14 +366,14 @@ func SettingsKeysPost(ctx *context.Context, form auth.AddKeyForm) {
keys, err := models.ListPublicKeys(ctx.User.ID) keys, err := models.ListPublicKeys(ctx.User.ID)
if err != nil { if err != nil {
ctx.Handle(500, "ListPublicKeys", err) ctx.ServerError("ListPublicKeys", err)
return return
} }
ctx.Data["Keys"] = keys ctx.Data["Keys"] = keys
gpgkeys, err := models.ListGPGKeys(ctx.User.ID) gpgkeys, err := models.ListGPGKeys(ctx.User.ID)
if err != nil { if err != nil {
ctx.Handle(500, "ListGPGKeys", err) ctx.ServerError("ListGPGKeys", err)
return return
} }
ctx.Data["GPGKeys"] = gpgkeys ctx.Data["GPGKeys"] = gpgkeys
@ -398,7 +398,7 @@ func SettingsKeysPost(ctx *context.Context, form auth.AddKeyForm) {
ctx.Data["Err_Content"] = true ctx.Data["Err_Content"] = true
ctx.RenderWithErr(ctx.Tr("settings.gpg_no_key_email_found"), tplSettingsKeys, &form) ctx.RenderWithErr(ctx.Tr("settings.gpg_no_key_email_found"), tplSettingsKeys, &form)
default: default:
ctx.Handle(500, "AddPublicKey", err) ctx.ServerError("AddPublicKey", err)
} }
return return
} }
@ -428,7 +428,7 @@ func SettingsKeysPost(ctx *context.Context, form auth.AddKeyForm) {
ctx.Data["Err_Title"] = true ctx.Data["Err_Title"] = true
ctx.RenderWithErr(ctx.Tr("settings.ssh_key_name_used"), tplSettingsKeys, &form) ctx.RenderWithErr(ctx.Tr("settings.ssh_key_name_used"), tplSettingsKeys, &form)
default: default:
ctx.Handle(500, "AddPublicKey", err) ctx.ServerError("AddPublicKey", err)
} }
return return
} }
@ -474,7 +474,7 @@ func SettingsApplications(ctx *context.Context) {
tokens, err := models.ListAccessTokens(ctx.User.ID) tokens, err := models.ListAccessTokens(ctx.User.ID)
if err != nil { if err != nil {
ctx.Handle(500, "ListAccessTokens", err) ctx.ServerError("ListAccessTokens", err)
return return
} }
ctx.Data["Tokens"] = tokens ctx.Data["Tokens"] = tokens
@ -490,7 +490,7 @@ func SettingsApplicationsPost(ctx *context.Context, form auth.NewAccessTokenForm
if ctx.HasError() { if ctx.HasError() {
tokens, err := models.ListAccessTokens(ctx.User.ID) tokens, err := models.ListAccessTokens(ctx.User.ID)
if err != nil { if err != nil {
ctx.Handle(500, "ListAccessTokens", err) ctx.ServerError("ListAccessTokens", err)
return return
} }
ctx.Data["Tokens"] = tokens ctx.Data["Tokens"] = tokens
@ -503,7 +503,7 @@ func SettingsApplicationsPost(ctx *context.Context, form auth.NewAccessTokenForm
Name: form.Name, Name: form.Name,
} }
if err := models.NewAccessToken(t); err != nil { if err := models.NewAccessToken(t); err != nil {
ctx.Handle(500, "NewAccessToken", err) ctx.ServerError("NewAccessToken", err)
return return
} }
@ -533,17 +533,17 @@ func SettingsTwoFactorRegenerateScratch(ctx *context.Context) {
t, err := models.GetTwoFactorByUID(ctx.User.ID) t, err := models.GetTwoFactorByUID(ctx.User.ID)
if err != nil { if err != nil {
ctx.Handle(500, "SettingsTwoFactor", err) ctx.ServerError("SettingsTwoFactor", err)
return return
} }
if err = t.GenerateScratchToken(); err != nil { if err = t.GenerateScratchToken(); err != nil {
ctx.Handle(500, "SettingsTwoFactor", err) ctx.ServerError("SettingsTwoFactor", err)
return return
} }
if err = models.UpdateTwoFactor(t); err != nil { if err = models.UpdateTwoFactor(t); err != nil {
ctx.Handle(500, "SettingsTwoFactor", err) ctx.ServerError("SettingsTwoFactor", err)
return return
} }
@ -558,12 +558,12 @@ func SettingsTwoFactorDisable(ctx *context.Context) {
t, err := models.GetTwoFactorByUID(ctx.User.ID) t, err := models.GetTwoFactorByUID(ctx.User.ID)
if err != nil { if err != nil {
ctx.Handle(500, "SettingsTwoFactor", err) ctx.ServerError("SettingsTwoFactor", err)
return return
} }
if err = models.DeleteTwoFactorByID(t.ID, ctx.User.ID); err != nil { if err = models.DeleteTwoFactorByID(t.ID, ctx.User.ID); err != nil {
ctx.Handle(500, "SettingsTwoFactor", err) ctx.ServerError("SettingsTwoFactor", err)
return return
} }
@ -585,7 +585,7 @@ func twofaGenerateSecretAndQr(ctx *context.Context) bool {
AccountName: ctx.User.Name, AccountName: ctx.User.Name,
}) })
if err != nil { if err != nil {
ctx.Handle(500, "SettingsTwoFactor", err) ctx.ServerError("SettingsTwoFactor", err)
return false return false
} }
} }
@ -593,13 +593,13 @@ func twofaGenerateSecretAndQr(ctx *context.Context) bool {
ctx.Data["TwofaSecret"] = otpKey.Secret() ctx.Data["TwofaSecret"] = otpKey.Secret()
img, err := otpKey.Image(320, 240) img, err := otpKey.Image(320, 240)
if err != nil { if err != nil {
ctx.Handle(500, "SettingsTwoFactor", err) ctx.ServerError("SettingsTwoFactor", err)
return false return false
} }
var imgBytes bytes.Buffer var imgBytes bytes.Buffer
if err = png.Encode(&imgBytes, img); err != nil { if err = png.Encode(&imgBytes, img); err != nil {
ctx.Handle(500, "SettingsTwoFactor", err) ctx.ServerError("SettingsTwoFactor", err)
return false return false
} }
@ -617,11 +617,11 @@ func SettingsTwoFactorEnroll(ctx *context.Context) {
t, err := models.GetTwoFactorByUID(ctx.User.ID) t, err := models.GetTwoFactorByUID(ctx.User.ID)
if t != nil { if t != nil {
// already enrolled // already enrolled
ctx.Handle(500, "SettingsTwoFactor", err) ctx.ServerError("SettingsTwoFactor", err)
return return
} }
if err != nil && !models.IsErrTwoFactorNotEnrolled(err) { if err != nil && !models.IsErrTwoFactorNotEnrolled(err) {
ctx.Handle(500, "SettingsTwoFactor", err) ctx.ServerError("SettingsTwoFactor", err)
return return
} }
@ -640,11 +640,11 @@ func SettingsTwoFactorEnrollPost(ctx *context.Context, form auth.TwoFactorAuthFo
t, err := models.GetTwoFactorByUID(ctx.User.ID) t, err := models.GetTwoFactorByUID(ctx.User.ID)
if t != nil { if t != nil {
// already enrolled // already enrolled
ctx.Handle(500, "SettingsTwoFactor", err) ctx.ServerError("SettingsTwoFactor", err)
return return
} }
if err != nil && !models.IsErrTwoFactorNotEnrolled(err) { if err != nil && !models.IsErrTwoFactorNotEnrolled(err) {
ctx.Handle(500, "SettingsTwoFactor", err) ctx.ServerError("SettingsTwoFactor", err)
return return
} }
@ -671,17 +671,17 @@ func SettingsTwoFactorEnrollPost(ctx *context.Context, form auth.TwoFactorAuthFo
} }
err = t.SetSecret(secret) err = t.SetSecret(secret)
if err != nil { if err != nil {
ctx.Handle(500, "SettingsTwoFactor", err) ctx.ServerError("SettingsTwoFactor", err)
return return
} }
err = t.GenerateScratchToken() err = t.GenerateScratchToken()
if err != nil { if err != nil {
ctx.Handle(500, "SettingsTwoFactor", err) ctx.ServerError("SettingsTwoFactor", err)
return return
} }
if err = models.NewTwoFactor(t); err != nil { if err = models.NewTwoFactor(t); err != nil {
ctx.Handle(500, "SettingsTwoFactor", err) ctx.ServerError("SettingsTwoFactor", err)
return return
} }
@ -698,7 +698,7 @@ func SettingsAccountLinks(ctx *context.Context) {
accountLinks, err := models.ListAccountLinks(ctx.User) accountLinks, err := models.ListAccountLinks(ctx.User)
if err != nil { if err != nil {
ctx.Handle(500, "ListAccountLinks", err) ctx.ServerError("ListAccountLinks", err)
return return
} }
@ -745,7 +745,7 @@ func SettingsDelete(ctx *context.Context) {
if models.IsErrUserNotExist(err) { if models.IsErrUserNotExist(err) {
ctx.RenderWithErr(ctx.Tr("form.enterred_invalid_password"), tplSettingsDelete, nil) ctx.RenderWithErr(ctx.Tr("form.enterred_invalid_password"), tplSettingsDelete, nil)
} else { } else {
ctx.Handle(500, "UserSignIn", err) ctx.ServerError("UserSignIn", err)
} }
return return
} }
@ -759,7 +759,7 @@ func SettingsDelete(ctx *context.Context) {
ctx.Flash.Error(ctx.Tr("form.still_has_org")) ctx.Flash.Error(ctx.Tr("form.still_has_org"))
ctx.Redirect(setting.AppSubURL + "/user/settings/delete") ctx.Redirect(setting.AppSubURL + "/user/settings/delete")
default: default:
ctx.Handle(500, "DeleteUser", err) ctx.ServerError("DeleteUser", err)
} }
} else { } else {
log.Trace("Account deleted: %s", ctx.User.Name) log.Trace("Account deleted: %s", ctx.User.Name)
@ -777,7 +777,7 @@ func SettingsOrganization(ctx *context.Context) {
ctx.Data["PageIsSettingsOrganization"] = true ctx.Data["PageIsSettingsOrganization"] = true
orgs, err := models.GetOrgsByUserID(ctx.User.ID, ctx.IsSigned) orgs, err := models.GetOrgsByUserID(ctx.User.ID, ctx.IsSigned)
if err != nil { if err != nil {
ctx.Handle(500, "GetOrgsByUserID", err) ctx.ServerError("GetOrgsByUserID", err)
return return
} }
ctx.Data["Orgs"] = orgs ctx.Data["Orgs"] = orgs
@ -792,7 +792,7 @@ func SettingsRepos(ctx *context.Context) {
var err error var err error
if err = ctxUser.GetRepositories(1, setting.UI.User.RepoPagingNum); err != nil { if err = ctxUser.GetRepositories(1, setting.UI.User.RepoPagingNum); err != nil {
ctx.Handle(500, "GetRepositories", err) ctx.ServerError("GetRepositories", err)
return return
} }
repos := ctxUser.Repos repos := ctxUser.Repos
@ -801,12 +801,12 @@ func SettingsRepos(ctx *context.Context) {
if repos[i].IsFork { if repos[i].IsFork {
err := repos[i].GetBaseRepo() err := repos[i].GetBaseRepo()
if err != nil { if err != nil {
ctx.Handle(500, "GetBaseRepo", err) ctx.ServerError("GetBaseRepo", err)
return return
} }
err = repos[i].BaseRepo.GetOwner() err = repos[i].BaseRepo.GetOwner()
if err != nil { if err != nil {
ctx.Handle(500, "GetOwner", err) ctx.ServerError("GetOwner", err)
return return
} }
} }

View File

@ -30,7 +30,7 @@ func SettingsOpenID(ctx *context.Context) {
openid, err := models.GetUserOpenIDs(ctx.User.ID) openid, err := models.GetUserOpenIDs(ctx.User.ID)
if err != nil { if err != nil {
ctx.Handle(500, "GetUserOpenIDs", err) ctx.ServerError("GetUserOpenIDs", err)
return return
} }
ctx.Data["OpenIDs"] = openid ctx.Data["OpenIDs"] = openid
@ -46,7 +46,7 @@ func SettingsOpenIDPost(ctx *context.Context, form auth.AddOpenIDForm) {
if ctx.HasError() { if ctx.HasError() {
openid, err := models.GetUserOpenIDs(ctx.User.ID) openid, err := models.GetUserOpenIDs(ctx.User.ID)
if err != nil { if err != nil {
ctx.Handle(500, "GetUserOpenIDs", err) ctx.ServerError("GetUserOpenIDs", err)
return return
} }
ctx.Data["OpenIDs"] = openid ctx.Data["OpenIDs"] = openid
@ -70,7 +70,7 @@ func SettingsOpenIDPost(ctx *context.Context, form auth.AddOpenIDForm) {
oids, err := models.GetUserOpenIDs(ctx.User.ID) oids, err := models.GetUserOpenIDs(ctx.User.ID)
if err != nil { if err != nil {
ctx.Handle(500, "GetUserOpenIDs", err) ctx.ServerError("GetUserOpenIDs", err)
return return
} }
ctx.Data["OpenIDs"] = oids ctx.Data["OpenIDs"] = oids
@ -100,7 +100,7 @@ func settingsOpenIDVerify(ctx *context.Context) {
oids, err := models.GetUserOpenIDs(ctx.User.ID) oids, err := models.GetUserOpenIDs(ctx.User.ID)
if err != nil { if err != nil {
ctx.Handle(500, "GetUserOpenIDs", err) ctx.ServerError("GetUserOpenIDs", err)
return return
} }
ctx.Data["OpenIDs"] = oids 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}) ctx.RenderWithErr(ctx.Tr("form.openid_been_used", id), tplSettingsOpenID, &auth.AddOpenIDForm{Openid: id})
return return
} }
ctx.Handle(500, "AddUserOpenID", err) ctx.ServerError("AddUserOpenID", err)
return return
} }
log.Trace("Associated OpenID %s to user %s", id, ctx.User.Name) 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 // DeleteOpenID response for delete user's openid
func DeleteOpenID(ctx *context.Context) { func DeleteOpenID(ctx *context.Context) {
if err := models.DeleteUserOpenID(&models.UserOpenID{ID: ctx.QueryInt64("id"), UID: ctx.User.ID}); err != nil { 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 return
} }
log.Trace("OpenID address deleted: %s", ctx.User.Name) 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 // ToggleOpenIDVisibility response for toggle visibility of user's openid
func ToggleOpenIDVisibility(ctx *context.Context) { func ToggleOpenIDVisibility(ctx *context.Context) {
if err := models.ToggleUserOpenIDVisibility(ctx.QueryInt64("id")); err != nil { if err := models.ToggleUserOpenIDVisibility(ctx.QueryInt64("id")); err != nil {
ctx.Handle(500, "ToggleUserOpenIDVisibility", err) ctx.ServerError("ToggleUserOpenIDVisibility", err)
return return
} }