mirror of
https://github.com/go-gitea/gitea
synced 2025-07-22 18:28:37 +00:00
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:
committed by
Lauris BH
parent
45c264f681
commit
65861900cd
@@ -35,7 +35,7 @@ func Authentications(ctx *context.Context) {
|
||||
var err error
|
||||
ctx.Data["Sources"], err = models.LoginSources()
|
||||
if err != nil {
|
||||
ctx.Handle(500, "LoginSources", err)
|
||||
ctx.ServerError("LoginSources", err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -197,7 +197,7 @@ func NewAuthSourcePost(ctx *context.Context, form auth.AuthenticationForm) {
|
||||
ctx.Data["Err_Name"] = true
|
||||
ctx.RenderWithErr(ctx.Tr("admin.auths.login_source_exist", err.(models.ErrLoginSourceAlreadyExist).Name), tplAuthNew, form)
|
||||
} else {
|
||||
ctx.Handle(500, "CreateSource", err)
|
||||
ctx.ServerError("CreateSource", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -221,7 +221,7 @@ func EditAuthSource(ctx *context.Context) {
|
||||
|
||||
source, err := models.GetLoginSourceByID(ctx.ParamsInt64(":authid"))
|
||||
if err != nil {
|
||||
ctx.Handle(500, "GetLoginSourceByID", err)
|
||||
ctx.ServerError("GetLoginSourceByID", err)
|
||||
return
|
||||
}
|
||||
ctx.Data["Source"] = source
|
||||
@@ -245,7 +245,7 @@ func EditAuthSourcePost(ctx *context.Context, form auth.AuthenticationForm) {
|
||||
|
||||
source, err := models.GetLoginSourceByID(ctx.ParamsInt64(":authid"))
|
||||
if err != nil {
|
||||
ctx.Handle(500, "GetLoginSourceByID", err)
|
||||
ctx.ServerError("GetLoginSourceByID", err)
|
||||
return
|
||||
}
|
||||
ctx.Data["Source"] = source
|
||||
@@ -282,7 +282,7 @@ func EditAuthSourcePost(ctx *context.Context, form auth.AuthenticationForm) {
|
||||
ctx.Flash.Error(err.Error(), true)
|
||||
ctx.HTML(200, tplAuthEdit)
|
||||
} else {
|
||||
ctx.Handle(500, "UpdateSource", err)
|
||||
ctx.ServerError("UpdateSource", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -296,7 +296,7 @@ func EditAuthSourcePost(ctx *context.Context, form auth.AuthenticationForm) {
|
||||
func DeleteAuthSource(ctx *context.Context) {
|
||||
source, err := models.GetLoginSourceByID(ctx.ParamsInt64(":authid"))
|
||||
if err != nil {
|
||||
ctx.Handle(500, "GetLoginSourceByID", err)
|
||||
ctx.ServerError("GetLoginSourceByID", err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@@ -34,7 +34,7 @@ func Notices(ctx *context.Context) {
|
||||
|
||||
notices, err := models.Notices(page, setting.UI.Admin.NoticePagingNum)
|
||||
if err != nil {
|
||||
ctx.Handle(500, "Notices", err)
|
||||
ctx.ServerError("Notices", err)
|
||||
return
|
||||
}
|
||||
ctx.Data["Notices"] = notices
|
||||
@@ -66,7 +66,7 @@ func DeleteNotices(ctx *context.Context) {
|
||||
// EmptyNotices delete all the notices
|
||||
func EmptyNotices(ctx *context.Context) {
|
||||
if err := models.DeleteNotices(0, 0); err != nil {
|
||||
ctx.Handle(500, "DeleteNotices", err)
|
||||
ctx.ServerError("DeleteNotices", err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@@ -34,12 +34,12 @@ func Repos(ctx *context.Context) {
|
||||
func DeleteRepo(ctx *context.Context) {
|
||||
repo, err := models.GetRepositoryByID(ctx.QueryInt64("id"))
|
||||
if err != nil {
|
||||
ctx.Handle(500, "GetRepositoryByID", err)
|
||||
ctx.ServerError("GetRepositoryByID", err)
|
||||
return
|
||||
}
|
||||
|
||||
if err := models.DeleteRepository(ctx.User, repo.MustOwner().ID, repo.ID); err != nil {
|
||||
ctx.Handle(500, "DeleteRepository", err)
|
||||
ctx.ServerError("DeleteRepository", err)
|
||||
return
|
||||
}
|
||||
log.Trace("Repository deleted: %s/%s", repo.MustOwner().Name, repo.Name)
|
||||
|
@@ -47,7 +47,7 @@ func NewUser(ctx *context.Context) {
|
||||
|
||||
sources, err := models.LoginSources()
|
||||
if err != nil {
|
||||
ctx.Handle(500, "LoginSources", err)
|
||||
ctx.ServerError("LoginSources", err)
|
||||
return
|
||||
}
|
||||
ctx.Data["Sources"] = sources
|
||||
@@ -64,7 +64,7 @@ func NewUserPost(ctx *context.Context, form auth.AdminCreateUserForm) {
|
||||
|
||||
sources, err := models.LoginSources()
|
||||
if err != nil {
|
||||
ctx.Handle(500, "LoginSources", err)
|
||||
ctx.ServerError("LoginSources", err)
|
||||
return
|
||||
}
|
||||
ctx.Data["Sources"] = sources
|
||||
@@ -108,7 +108,7 @@ func NewUserPost(ctx *context.Context, form auth.AdminCreateUserForm) {
|
||||
ctx.Data["Err_UserName"] = true
|
||||
ctx.RenderWithErr(ctx.Tr("user.form.name_pattern_not_allowed", err.(models.ErrNamePatternNotAllowed).Pattern), tplUserNew, &form)
|
||||
default:
|
||||
ctx.Handle(500, "CreateUser", err)
|
||||
ctx.ServerError("CreateUser", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -126,7 +126,7 @@ func NewUserPost(ctx *context.Context, form auth.AdminCreateUserForm) {
|
||||
func prepareUserInfo(ctx *context.Context) *models.User {
|
||||
u, err := models.GetUserByID(ctx.ParamsInt64(":userid"))
|
||||
if err != nil {
|
||||
ctx.Handle(500, "GetUserByID", err)
|
||||
ctx.ServerError("GetUserByID", err)
|
||||
return nil
|
||||
}
|
||||
ctx.Data["User"] = u
|
||||
@@ -134,7 +134,7 @@ func prepareUserInfo(ctx *context.Context) *models.User {
|
||||
if u.LoginSource > 0 {
|
||||
ctx.Data["LoginSource"], err = models.GetLoginSourceByID(u.LoginSource)
|
||||
if err != nil {
|
||||
ctx.Handle(500, "GetLoginSourceByID", err)
|
||||
ctx.ServerError("GetLoginSourceByID", err)
|
||||
return nil
|
||||
}
|
||||
} else {
|
||||
@@ -143,7 +143,7 @@ func prepareUserInfo(ctx *context.Context) *models.User {
|
||||
|
||||
sources, err := models.LoginSources()
|
||||
if err != nil {
|
||||
ctx.Handle(500, "LoginSources", err)
|
||||
ctx.ServerError("LoginSources", err)
|
||||
return nil
|
||||
}
|
||||
ctx.Data["Sources"] = sources
|
||||
@@ -197,7 +197,7 @@ func EditUserPost(ctx *context.Context, form auth.AdminEditUserForm) {
|
||||
u.Passwd = form.Password
|
||||
var err error
|
||||
if u.Salt, err = models.GetUserSalt(); err != nil {
|
||||
ctx.Handle(500, "UpdateUser", err)
|
||||
ctx.ServerError("UpdateUser", err)
|
||||
return
|
||||
}
|
||||
u.HashPassword()
|
||||
@@ -221,7 +221,7 @@ func EditUserPost(ctx *context.Context, form auth.AdminEditUserForm) {
|
||||
ctx.Data["Err_Email"] = true
|
||||
ctx.RenderWithErr(ctx.Tr("form.email_been_used"), tplUserEdit, &form)
|
||||
} else {
|
||||
ctx.Handle(500, "UpdateUser", err)
|
||||
ctx.ServerError("UpdateUser", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -235,7 +235,7 @@ func EditUserPost(ctx *context.Context, form auth.AdminEditUserForm) {
|
||||
func DeleteUser(ctx *context.Context) {
|
||||
u, err := models.GetUserByID(ctx.ParamsInt64(":userid"))
|
||||
if err != nil {
|
||||
ctx.Handle(500, "GetUserByID", err)
|
||||
ctx.ServerError("GetUserByID", err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -252,7 +252,7 @@ func DeleteUser(ctx *context.Context) {
|
||||
"redirect": setting.AppSubURL + "/admin/users/" + ctx.Params(":userid"),
|
||||
})
|
||||
default:
|
||||
ctx.Handle(500, "DeleteUser", err)
|
||||
ctx.ServerError("DeleteUser", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
Reference in New Issue
Block a user