mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-05-31 20:02:09 +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:
parent
45c264f681
commit
65861900cd
48 changed files with 622 additions and 610 deletions
|
@ -29,9 +29,9 @@ func GetUserByName(ctx *context.Context, name string) *models.User {
|
|||
user, err := models.GetUserByName(name)
|
||||
if err != nil {
|
||||
if models.IsErrUserNotExist(err) {
|
||||
ctx.Handle(404, "GetUserByName", nil)
|
||||
ctx.NotFound("GetUserByName", nil)
|
||||
} else {
|
||||
ctx.Handle(500, "GetUserByName", err)
|
||||
ctx.ServerError("GetUserByName", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@ -79,7 +79,7 @@ func Profile(ctx *context.Context) {
|
|||
// Show OpenID URIs
|
||||
openIDs, err := models.GetUserOpenIDs(ctxUser.ID)
|
||||
if err != nil {
|
||||
ctx.Handle(500, "GetUserOpenIDs", err)
|
||||
ctx.ServerError("GetUserOpenIDs", err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -91,7 +91,7 @@ func Profile(ctx *context.Context) {
|
|||
|
||||
orgs, err := models.GetOrgsByUserID(ctxUser.ID, showPrivate)
|
||||
if err != nil {
|
||||
ctx.Handle(500, "GetOrgsByUserIDDesc", err)
|
||||
ctx.ServerError("GetOrgsByUserIDDesc", err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -147,13 +147,13 @@ func Profile(ctx *context.Context) {
|
|||
if len(keyword) == 0 {
|
||||
repos, err = ctxUser.GetStarredRepos(showPrivate, page, setting.UI.User.RepoPagingNum, orderBy.String())
|
||||
if err != nil {
|
||||
ctx.Handle(500, "GetStarredRepos", err)
|
||||
ctx.ServerError("GetStarredRepos", err)
|
||||
return
|
||||
}
|
||||
|
||||
count, err = ctxUser.GetStarredRepoCount(showPrivate)
|
||||
if err != nil {
|
||||
ctx.Handle(500, "GetStarredRepoCount", err)
|
||||
ctx.ServerError("GetStarredRepoCount", err)
|
||||
return
|
||||
}
|
||||
} else {
|
||||
|
@ -168,7 +168,7 @@ func Profile(ctx *context.Context) {
|
|||
Collaborate: util.OptionalBoolFalse,
|
||||
})
|
||||
if err != nil {
|
||||
ctx.Handle(500, "SearchRepositoryByName", err)
|
||||
ctx.ServerError("SearchRepositoryByName", err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
@ -181,7 +181,7 @@ func Profile(ctx *context.Context) {
|
|||
var total int
|
||||
repos, err = models.GetUserRepositories(ctxUser.ID, showPrivate, page, setting.UI.User.RepoPagingNum, orderBy.String())
|
||||
if err != nil {
|
||||
ctx.Handle(500, "GetRepositories", err)
|
||||
ctx.ServerError("GetRepositories", err)
|
||||
return
|
||||
}
|
||||
ctx.Data["Repos"] = repos
|
||||
|
@ -191,7 +191,7 @@ func Profile(ctx *context.Context) {
|
|||
} else {
|
||||
count, err := models.GetPublicRepositoryCount(ctxUser)
|
||||
if err != nil {
|
||||
ctx.Handle(500, "GetPublicRepositoryCount", err)
|
||||
ctx.ServerError("GetPublicRepositoryCount", err)
|
||||
return
|
||||
}
|
||||
total = int(count)
|
||||
|
@ -210,7 +210,7 @@ func Profile(ctx *context.Context) {
|
|||
PageSize: setting.UI.User.RepoPagingNum,
|
||||
})
|
||||
if err != nil {
|
||||
ctx.Handle(500, "SearchRepositoryByName", err)
|
||||
ctx.ServerError("SearchRepositoryByName", err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -267,7 +267,7 @@ func Action(ctx *context.Context) {
|
|||
}
|
||||
|
||||
if err != nil {
|
||||
ctx.Handle(500, fmt.Sprintf("Action (%s)", ctx.Params(":action")), err)
|
||||
ctx.ServerError(fmt.Sprintf("Action (%s)", ctx.Params(":action")), err)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue