refactor: remove NotFoundOrServerError (#39727)

follow up #39722
This commit is contained in:
wxiaoguang authored and GitHub committed 2026-10-10 16:34:53 +02:00
1 parent c30ddc3e14
commit e60d1c7fc8
13 files changed
+29 -41

No files matched your search

+1 -1
View File
@@ -366,7 +366,7 @@ func ViewUser(ctx *context.Context) {
func getTargetBot(ctx *context.Context) *user_model.User {
u, err := user_model.GetUserByID(ctx, ctx.PathParamInt64("userid"))
if err != nil {
ctx.NotFoundOrServerError("GetUserByID", user_model.IsErrUserNotExist, err)
ctx.ServerError("GetUserByID", err)
return nil
}
if !u.IsTypeBot() {
+6 -6
View File
@@ -195,12 +195,12 @@ func ChangeProjectStatus(ctx *context.Context) {
project, err := project_model.GetProjectByIDAndOwner(ctx, id, ctx.ContextUser.ID)
if err != nil {
ctx.NotFoundOrServerError("GetProjectByID", project_model.IsErrProjectNotExist, err)
ctx.ServerError("GetProjectByID", err)
return
}
if err := project_model.ChangeProjectStatusByRepoIDAndID(ctx, 0, project.ID, toClose); err != nil {
ctx.NotFoundOrServerError("ChangeProjectStatusByRepoIDAndID", project_model.IsErrProjectNotExist, err)
ctx.ServerError("ChangeProjectStatusByRepoIDAndID", err)
return
}
ctx.JSONRedirect(project_model.ProjectLinkForOrg(ctx.ContextUser, project.ID))
@@ -210,7 +210,7 @@ func ChangeProjectStatus(ctx *context.Context) {
func DeleteProject(ctx *context.Context) {
p, err := project_model.GetProjectByIDAndOwner(ctx, ctx.PathParamInt64("id"), ctx.ContextUser.ID)
if err != nil {
ctx.NotFoundOrServerError("GetProjectByID", project_model.IsErrProjectNotExist, err)
ctx.ServerError("GetProjectByID", err)
return
}
@@ -239,7 +239,7 @@ func RenderEditProject(ctx *context.Context) {
p, err := project_model.GetProjectByIDAndOwner(ctx, ctx.PathParamInt64("id"), ctx.ContextUser.ID)
if err != nil {
ctx.NotFoundOrServerError("GetProjectByID", project_model.IsErrProjectNotExist, err)
ctx.ServerError("GetProjectByID", err)
return
}
@@ -277,7 +277,7 @@ func EditProjectPost(ctx *context.Context) {
p, err := project_model.GetProjectByIDAndOwner(ctx, projectID, ctx.ContextUser.ID)
if err != nil {
ctx.NotFoundOrServerError("GetProjectByID", project_model.IsErrProjectNotExist, err)
ctx.ServerError("GetProjectByID", err)
return
}
@@ -302,7 +302,7 @@ func EditProjectPost(ctx *context.Context) {
func ViewProject(ctx *context.Context) {
project, err := project_model.GetProjectByIDAndOwner(ctx, ctx.PathParamInt64("id"), ctx.ContextUser.ID)
if err != nil {
ctx.NotFoundOrServerError("GetProjectByID", project_model.IsErrProjectNotExist, err)
ctx.ServerError("GetProjectByID", err)
return
}
+1 -1
View File
@@ -270,7 +270,7 @@ func LoadBranchesAndTags(ctx *context.Context) {
ctx.JSON(http.StatusOK, response)
return
}
ctx.NotFoundOrServerError(fmt.Sprintf("could not load branches and tags the commit %s belongs to", ctx.PathParam("sha")), git.IsErrNotExist, err)
ctx.ServerError("LoadBranchesAndTags", err)
}
// Diff show different from current commit to previous commit
+1 -1
View File
@@ -405,7 +405,7 @@ func DeleteFilePost(ctx *context.Context) {
// Check if the path is a directory
entry, err := ctx.Repo.Commit.GetTreeEntryByPath(ctx, ctx.Repo.GitRepo, treePath)
if err != nil {
ctx.NotFoundOrServerError("GetTreeEntryByPath", git.IsErrNotExist, err)
ctx.ServerError("GetTreeEntryByPath", err)
return
}
+1 -1
View File
@@ -182,7 +182,7 @@ func retrieveProjectsInternal(ctx *context.Context, repo *repo_model.Repository)
func GetActionIssue(ctx *context.Context) *issues_model.Issue {
issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
if err != nil {
ctx.NotFoundOrServerError("GetIssueByIndex", issues_model.IsErrIssueNotExist, err)
ctx.ServerError("GetIssueByIndex", err)
return nil
}
issue.Repo = ctx.Repo.Repository
+8 -8
View File
@@ -150,12 +150,12 @@ func NewComment(ctx *context.Context) {
func UpdateCommentContent(ctx *context.Context) {
comment, err := issues_model.GetCommentByID(ctx, ctx.PathParamInt64("id"))
if err != nil {
ctx.NotFoundOrServerError("GetCommentByID", issues_model.IsErrCommentNotExist, err)
ctx.ServerError("GetCommentByID", err)
return
}
if err := comment.LoadIssue(ctx); err != nil {
ctx.NotFoundOrServerError("LoadIssue", issues_model.IsErrIssueNotExist, err)
ctx.ServerError("LoadIssue", err)
return
}
@@ -234,12 +234,12 @@ func UpdateCommentContent(ctx *context.Context) {
func DeleteComment(ctx *context.Context) {
comment, err := issues_model.GetCommentByID(ctx, ctx.PathParamInt64("id"))
if err != nil {
ctx.NotFoundOrServerError("GetCommentByID", issues_model.IsErrCommentNotExist, err)
ctx.ServerError("GetCommentByID", err)
return
}
if err := comment.LoadIssue(ctx); err != nil {
ctx.NotFoundOrServerError("LoadIssue", issues_model.IsErrIssueNotExist, err)
ctx.ServerError("LoadIssue", err)
return
}
@@ -269,12 +269,12 @@ func ChangeCommentReaction(ctx *context.Context) {
form := web.GetForm[*forms.ReactionForm](ctx)
comment, err := issues_model.GetCommentByID(ctx, ctx.PathParamInt64("id"))
if err != nil {
ctx.NotFoundOrServerError("GetCommentByID", issues_model.IsErrCommentNotExist, err)
ctx.ServerError("GetCommentByID", err)
return
}
if err := comment.LoadIssue(ctx); err != nil {
ctx.NotFoundOrServerError("LoadIssue", issues_model.IsErrIssueNotExist, err)
ctx.ServerError("LoadIssue", err)
return
}
@@ -374,12 +374,12 @@ func ChangeCommentReaction(ctx *context.Context) {
func GetCommentAttachments(ctx *context.Context) {
comment, err := issues_model.GetCommentByID(ctx, ctx.PathParamInt64("id"))
if err != nil {
ctx.NotFoundOrServerError("GetCommentByID", issues_model.IsErrCommentNotExist, err)
ctx.ServerError("GetCommentByID", err)
return
}
if err := comment.LoadIssue(ctx); err != nil {
ctx.NotFoundOrServerError("LoadIssue", issues_model.IsErrIssueNotExist, err)
ctx.ServerError("LoadIssue", err)
return
}
+1 -1
View File
@@ -286,7 +286,7 @@ func combineLabelComments(issue *issues_model.Issue) {
func prepareIssueViewLoad(ctx *context.Context) *issues_model.Issue {
issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
if err != nil {
ctx.NotFoundOrServerError("GetIssueByIndex", issues_model.IsErrIssueNotExist, err)
ctx.ServerError("GetIssueByIndex", err)
return nil
}
issue.Repo = ctx.Repo.Repository
+3 -3
View File
@@ -170,7 +170,7 @@ func ChangeProjectStatus(ctx *context.Context) {
id := ctx.PathParamInt64("id")
if err := project_model.ChangeProjectStatusByRepoIDAndID(ctx, ctx.Repo.Repository.ID, id, toClose); err != nil {
ctx.NotFoundOrServerError("ChangeProjectStatusByRepoIDAndID", project_model.IsErrProjectNotExist, err)
ctx.ServerError("ChangeProjectStatusByRepoIDAndID", err)
return
}
ctx.JSONRedirect(project_model.ProjectLinkForRepo(ctx.Repo.Repository, id))
@@ -475,12 +475,12 @@ func UpdateIssueProject(ctx *context.Context) {
func UpdateIssueProjectColumn(ctx *context.Context) {
issue, err := issues_model.GetIssueByRepoID(ctx, ctx.Repo.Repository.ID, ctx.FormInt64("issue_id"))
if err != nil {
ctx.NotFoundOrServerError("GetIssueByID", issues_model.IsErrIssueNotExist, err)
ctx.ServerError("GetIssueByID", err)
return
}
column, err := project_model.GetColumn(ctx, ctx.FormInt64("id"))
if err != nil {
ctx.NotFoundOrServerError("GetColumn", project_model.IsErrProjectColumnNotExist, err)
ctx.ServerError("GetColumn", err)
return
}
+1 -1
View File
@@ -295,7 +295,7 @@ func handleRepoActionError(ctx *context.Context, err error) {
case errors.Is(err, util.ErrPermissionDenied):
ctx.JSONError(ctx.Tr("error.permission_denied"))
default:
ctx.ServerError(fmt.Sprintf("Action (%s)", ctx.PathParam("action")), err)
ctx.ServerError("RepoAction:"+ctx.PathParam("action"), err)
}
}
+3 -3
View File
@@ -26,7 +26,7 @@ func findProject(ctx *context.Context) *project_model.Project {
project, err = project_model.GetProjectByIDAndOwner(ctx, ctx.PathParamInt64("id"), ctx.ContextUser.ID)
}
if err != nil {
ctx.NotFoundOrServerError("GetProject", project_model.IsErrProjectNotExist, err)
ctx.ServerError("GetProject", err)
return nil
}
return project
@@ -39,7 +39,7 @@ func findColumn(ctx *context.Context) (*project_model.Project, *project_model.Co
}
column, err := project_model.GetColumnByIDAndProjectID(ctx, ctx.PathParamInt64("columnID"), project.ID)
if err != nil {
ctx.NotFoundOrServerError("GetColumnByIDAndProjectID", project_model.IsErrProjectColumnNotExist, err)
ctx.ServerError("GetColumnByIDAndProjectID", err)
return nil, nil
}
return project, column
@@ -175,7 +175,7 @@ func MoveIssues(ctx *context.Context) {
}
movedIssues, err := issues_model.GetIssuesByIDs(ctx, issueIDs)
if err != nil {
ctx.NotFoundOrServerError("GetIssueByID", issues_model.IsErrIssueNotExist, err)
ctx.ServerError("GetIssueByID", err)
return
}
+1 -1
View File
@@ -27,7 +27,7 @@ func AvatarByUsernameSize(ctx *context.Context) {
if user == nil {
var err error
if user, err = user_model.GetUserByName(ctx, username); err != nil {
ctx.NotFoundOrServerError("GetUserByName", user_model.IsErrUserNotExist, err)
ctx.ServerError("GetUserByName", err)
return
}
}
+2 -2
View File
@@ -177,7 +177,7 @@ func (oa *OAuth2CommonHandlers) RegenerateSecret(ctx *context.Context) {
func (oa *OAuth2CommonHandlers) DeleteApp(ctx *context.Context) {
app, err := auth.GetOAuth2ApplicationByID(ctx, ctx.PathParamInt64("id"))
if err != nil {
ctx.NotFoundOrServerError("GetOAuth2ApplicationByID", auth.IsErrOAuthApplicationNotFound, err)
ctx.ServerError("GetOAuth2ApplicationByID", err)
return
}
@@ -208,7 +208,7 @@ func (oa *OAuth2CommonHandlers) RevokeGrant(ctx *context.Context) {
app, err := auth.GetOAuth2ApplicationByID(ctx, grant.ApplicationID)
if err != nil {
ctx.NotFoundOrServerError("GetOAuth2ApplicationByID", auth.IsErrOAuthApplicationNotFound, err)
ctx.ServerError("GetOAuth2ApplicationByID", err)
return
}
-12
View File
@@ -190,15 +190,3 @@ func (ctx *Context) serverErrorInternal(skip int, logMsg string, logErr error) {
ctx.Data["ErrorMsg"] = userErrorMsg
ctx.HTML(http.StatusInternalServerError, tplStatus500)
}
// NotFoundOrServerError use error check function to determine if the error
// is about not found. It responds with 404 status code for not found error,
// or error context description for logging purpose of 500 server error.
// TODO: remove the "errCheck" and use util.ErrNotFound to check
func (ctx *Context) NotFoundOrServerError(logMsg string, errCheck func(error) bool, logErr error) {
if errCheck(logErr) {
ctx.notFoundInternal(1, logMsg, logErr)
return
}
ctx.serverErrorInternal(1, logMsg, logErr)
}