1
1
mirror of https://github.com/go-gitea/gitea synced 2025-02-24 22:04:18 +00:00

Refactor error system (#33626)

This commit is contained in:
wxiaoguang 2025-02-18 04:41:03 +08:00 committed by GitHub
parent 7df09e31fa
commit 15e020eec8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
75 changed files with 703 additions and 693 deletions

View File

@ -10,13 +10,16 @@ import (
// Common Errors forming the base of our error system // Common Errors forming the base of our error system
// //
// Many Errors returned by Gitea can be tested against these errors // Many Errors returned by Gitea can be tested against these errors using "errors.Is".
// using errors.Is.
var ( var (
ErrInvalidArgument = errors.New("invalid argument") ErrInvalidArgument = errors.New("invalid argument") // also implies HTTP 400
ErrPermissionDenied = errors.New("permission denied") ErrPermissionDenied = errors.New("permission denied") // also implies HTTP 403
ErrAlreadyExist = errors.New("resource already exists") ErrNotExist = errors.New("resource does not exist") // also implies HTTP 404
ErrNotExist = errors.New("resource does not exist") ErrAlreadyExist = errors.New("resource already exists") // also implies HTTP 409
// ErrUnprocessableContent implies HTTP 422, syntax of the request content was correct,
// but server was unable to process the contained instructions
ErrUnprocessableContent = errors.New("unprocessable content")
) )
// SilentWrap provides a simple wrapper for a wrapped error where the wrapped error message plays no part in the error message // SilentWrap provides a simple wrapper for a wrapped error where the wrapped error message plays no part in the error message

View File

@ -42,7 +42,7 @@ func GetAllEmails(ctx *context.APIContext) {
ListOptions: listOptions, ListOptions: listOptions,
}) })
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }

View File

@ -59,14 +59,14 @@ func ListHooks(ctx *context.APIContext) {
sysHooks, err := webhook.GetSystemOrDefaultWebhooks(ctx, isSystemWebhook) sysHooks, err := webhook.GetSystemOrDefaultWebhooks(ctx, isSystemWebhook)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
hooks := make([]*api.Hook, len(sysHooks)) hooks := make([]*api.Hook, len(sysHooks))
for i, hook := range sysHooks { for i, hook := range sysHooks {
h, err := webhook_service.ToHook(setting.AppURL+"/-/admin", hook) h, err := webhook_service.ToHook(setting.AppURL+"/-/admin", hook)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
hooks[i] = h hooks[i] = h
@ -98,13 +98,13 @@ func GetHook(ctx *context.APIContext) {
if errors.Is(err, util.ErrNotExist) { if errors.Is(err, util.ErrNotExist) {
ctx.APIErrorNotFound() ctx.APIErrorNotFound()
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }
h, err := webhook_service.ToHook("/-/admin/", hook) h, err := webhook_service.ToHook("/-/admin/", hook)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
ctx.JSON(http.StatusOK, h) ctx.JSON(http.StatusOK, h)
@ -188,7 +188,7 @@ func DeleteHook(ctx *context.APIContext) {
if errors.Is(err, util.ErrNotExist) { if errors.Is(err, util.ErrNotExist) {
ctx.APIErrorNotFound() ctx.APIErrorNotFound()
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }

View File

@ -69,7 +69,7 @@ func CreateOrg(ctx *context.APIContext) {
db.IsErrNamePatternNotAllowed(err) { db.IsErrNamePatternNotAllowed(err) {
ctx.APIError(http.StatusUnprocessableEntity, err) ctx.APIError(http.StatusUnprocessableEntity, err)
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }
@ -109,7 +109,7 @@ func GetAllOrgs(ctx *context.APIContext) {
Visible: []api.VisibleType{api.VisibleTypePublic, api.VisibleTypeLimited, api.VisibleTypePrivate}, Visible: []api.VisibleType{api.VisibleTypePublic, api.VisibleTypeLimited, api.VisibleTypePrivate},
}) })
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
orgs := make([]*api.Organization, len(users)) orgs := make([]*api.Organization, len(users))

View File

@ -42,7 +42,7 @@ func parseAuthSource(ctx *context.APIContext, u *user_model.User, sourceID int64
if auth.IsErrSourceNotExist(err) { if auth.IsErrSourceNotExist(err) {
ctx.APIError(http.StatusUnprocessableEntity, err) ctx.APIError(http.StatusUnprocessableEntity, err)
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }
@ -145,7 +145,7 @@ func CreateUser(ctx *context.APIContext) {
db.IsErrNamePatternNotAllowed(err) { db.IsErrNamePatternNotAllowed(err) {
ctx.APIError(http.StatusUnprocessableEntity, err) ctx.APIError(http.StatusUnprocessableEntity, err)
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }
@ -210,7 +210,7 @@ func EditUser(ctx *context.APIContext) {
case errors.Is(err, password.ErrIsPwned), password.IsErrIsPwnedRequest(err): case errors.Is(err, password.ErrIsPwned), password.IsErrIsPwnedRequest(err):
ctx.APIError(http.StatusBadRequest, err) ctx.APIError(http.StatusBadRequest, err)
default: default:
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }
@ -223,7 +223,7 @@ func EditUser(ctx *context.APIContext) {
case user_model.IsErrEmailAlreadyUsed(err): case user_model.IsErrEmailAlreadyUsed(err):
ctx.APIError(http.StatusBadRequest, err) ctx.APIError(http.StatusBadRequest, err)
default: default:
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }
@ -252,7 +252,7 @@ func EditUser(ctx *context.APIContext) {
if user_model.IsErrDeleteLastAdminUser(err) { if user_model.IsErrDeleteLastAdminUser(err) {
ctx.APIError(http.StatusBadRequest, err) ctx.APIError(http.StatusBadRequest, err)
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }
@ -307,7 +307,7 @@ func DeleteUser(ctx *context.APIContext) {
user_model.IsErrDeleteLastAdminUser(err) { user_model.IsErrDeleteLastAdminUser(err) {
ctx.APIError(http.StatusUnprocessableEntity, err) ctx.APIError(http.StatusUnprocessableEntity, err)
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }
@ -381,7 +381,7 @@ func DeleteUserPublicKey(ctx *context.APIContext) {
} else if asymkey_model.IsErrKeyAccessDenied(err) { } else if asymkey_model.IsErrKeyAccessDenied(err) {
ctx.APIError(http.StatusForbidden, "You do not have access to this key") ctx.APIError(http.StatusForbidden, "You do not have access to this key")
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }
@ -432,7 +432,7 @@ func SearchUsers(ctx *context.APIContext) {
ListOptions: listOptions, ListOptions: listOptions,
}) })
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }

View File

@ -33,7 +33,7 @@ func ListUserBadges(ctx *context.APIContext) {
badges, maxResults, err := user_model.GetUserBadges(ctx, ctx.ContextUser) badges, maxResults, err := user_model.GetUserBadges(ctx, ctx.ContextUser)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
@ -70,7 +70,7 @@ func AddUserBadges(ctx *context.APIContext) {
badges := prepareBadgesForReplaceOrAdd(*form) badges := prepareBadgesForReplaceOrAdd(*form)
if err := user_model.AddUserBadges(ctx, ctx.ContextUser, badges); err != nil { if err := user_model.AddUserBadges(ctx, ctx.ContextUser, badges); err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
@ -106,7 +106,7 @@ func DeleteUserBadges(ctx *context.APIContext) {
badges := prepareBadgesForReplaceOrAdd(*form) badges := prepareBadgesForReplaceOrAdd(*form)
if err := user_model.RemoveUserBadges(ctx, ctx.ContextUser, badges); err != nil { if err := user_model.RemoveUserBadges(ctx, ctx.ContextUser, badges); err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }

View File

@ -66,6 +66,7 @@
package v1 package v1
import ( import (
"errors"
"fmt" "fmt"
"net/http" "net/http"
"strings" "strings"
@ -118,7 +119,7 @@ func sudo() func(ctx *context.APIContext) {
if user_model.IsErrUserNotExist(err) { if user_model.IsErrUserNotExist(err) {
ctx.APIErrorNotFound() ctx.APIErrorNotFound()
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }
@ -156,10 +157,10 @@ func repoAssignment() func(ctx *context.APIContext) {
} else if user_model.IsErrUserRedirectNotExist(err) { } else if user_model.IsErrUserRedirectNotExist(err) {
ctx.APIErrorNotFound("GetUserByName", err) ctx.APIErrorNotFound("GetUserByName", err)
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }
@ -177,10 +178,10 @@ func repoAssignment() func(ctx *context.APIContext) {
} else if repo_model.IsErrRedirectNotExist(err) { } else if repo_model.IsErrRedirectNotExist(err) {
ctx.APIErrorNotFound() ctx.APIErrorNotFound()
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }
@ -192,7 +193,7 @@ func repoAssignment() func(ctx *context.APIContext) {
taskID := ctx.Data["ActionsTaskID"].(int64) taskID := ctx.Data["ActionsTaskID"].(int64)
task, err := actions_model.GetTaskByID(ctx, taskID) task, err := actions_model.GetTaskByID(ctx, taskID)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
if task.RepoID != repo.ID { if task.RepoID != repo.ID {
@ -207,14 +208,14 @@ func repoAssignment() func(ctx *context.APIContext) {
} }
if err := ctx.Repo.Repository.LoadUnits(ctx); err != nil { if err := ctx.Repo.Repository.LoadUnits(ctx); err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
ctx.Repo.Permission.SetUnitsWithDefaultAccessMode(ctx.Repo.Repository.Units, ctx.Repo.Permission.AccessMode) ctx.Repo.Permission.SetUnitsWithDefaultAccessMode(ctx.Repo.Repository.Units, ctx.Repo.Permission.AccessMode)
} else { } else {
ctx.Repo.Permission, err = access_model.GetUserRepoPermission(ctx, repo, ctx.Doer) ctx.Repo.Permission, err = access_model.GetUserRepoPermission(ctx, repo, ctx.Doer)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
} }
@ -474,13 +475,14 @@ func reqOrgOwnership() func(ctx *context.APIContext) {
} else if ctx.Org.Team != nil { } else if ctx.Org.Team != nil {
orgID = ctx.Org.Team.OrgID orgID = ctx.Org.Team.OrgID
} else { } else {
ctx.APIError(http.StatusInternalServerError, "reqOrgOwnership: unprepared context") setting.PanicInDevOrTesting("reqOrgOwnership: unprepared context")
ctx.APIErrorInternal(errors.New("reqOrgOwnership: unprepared context"))
return return
} }
isOwner, err := organization.IsOrganizationOwner(ctx, orgID, ctx.Doer.ID) isOwner, err := organization.IsOrganizationOwner(ctx, orgID, ctx.Doer.ID)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} else if !isOwner { } else if !isOwner {
if ctx.Org.Organization != nil { if ctx.Org.Organization != nil {
@ -500,26 +502,27 @@ func reqTeamMembership() func(ctx *context.APIContext) {
return return
} }
if ctx.Org.Team == nil { if ctx.Org.Team == nil {
ctx.APIError(http.StatusInternalServerError, "reqTeamMembership: unprepared context") setting.PanicInDevOrTesting("reqTeamMembership: unprepared context")
ctx.APIErrorInternal(errors.New("reqTeamMembership: unprepared context"))
return return
} }
orgID := ctx.Org.Team.OrgID orgID := ctx.Org.Team.OrgID
isOwner, err := organization.IsOrganizationOwner(ctx, orgID, ctx.Doer.ID) isOwner, err := organization.IsOrganizationOwner(ctx, orgID, ctx.Doer.ID)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} else if isOwner { } else if isOwner {
return return
} }
if isTeamMember, err := organization.IsTeamMember(ctx, orgID, ctx.Org.Team.ID, ctx.Doer.ID); err != nil { if isTeamMember, err := organization.IsTeamMember(ctx, orgID, ctx.Org.Team.ID, ctx.Doer.ID); err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} else if !isTeamMember { } else if !isTeamMember {
isOrgMember, err := organization.IsOrganizationMember(ctx, orgID, ctx.Doer.ID) isOrgMember, err := organization.IsOrganizationMember(ctx, orgID, ctx.Doer.ID)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} else if isOrgMember { } else if isOrgMember {
ctx.APIError(http.StatusForbidden, "Must be a team member") ctx.APIError(http.StatusForbidden, "Must be a team member")
} else { } else {
@ -543,12 +546,13 @@ func reqOrgMembership() func(ctx *context.APIContext) {
} else if ctx.Org.Team != nil { } else if ctx.Org.Team != nil {
orgID = ctx.Org.Team.OrgID orgID = ctx.Org.Team.OrgID
} else { } else {
ctx.APIError(http.StatusInternalServerError, "reqOrgMembership: unprepared context") setting.PanicInDevOrTesting("reqOrgMembership: unprepared context")
ctx.APIErrorInternal(errors.New("reqOrgMembership: unprepared context"))
return return
} }
if isMember, err := organization.IsOrganizationMember(ctx, orgID, ctx.Doer.ID); err != nil { if isMember, err := organization.IsOrganizationMember(ctx, orgID, ctx.Doer.ID); err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} else if !isMember { } else if !isMember {
if ctx.Org.Organization != nil { if ctx.Org.Organization != nil {
@ -615,10 +619,10 @@ func orgAssignment(args ...bool) func(ctx *context.APIContext) {
} else if user_model.IsErrUserRedirectNotExist(err) { } else if user_model.IsErrUserRedirectNotExist(err) {
ctx.APIErrorNotFound("GetOrgByName", err) ctx.APIErrorNotFound("GetOrgByName", err)
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }
@ -631,7 +635,7 @@ func orgAssignment(args ...bool) func(ctx *context.APIContext) {
if organization.IsErrTeamNotExist(err) { if organization.IsErrTeamNotExist(err) {
ctx.APIErrorNotFound() ctx.APIErrorNotFound()
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }

View File

@ -5,7 +5,6 @@ package misc
import ( import (
"fmt" "fmt"
"net/http"
asymkey_service "code.gitea.io/gitea/services/asymkey" asymkey_service "code.gitea.io/gitea/services/asymkey"
"code.gitea.io/gitea/services/context" "code.gitea.io/gitea/services/context"
@ -53,11 +52,11 @@ func SigningKey(ctx *context.APIContext) {
content, err := asymkey_service.PublicSigningKey(ctx, path) content, err := asymkey_service.PublicSigningKey(ctx, path)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
_, err = ctx.Write([]byte(content)) _, err = ctx.Write([]byte(content))
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, fmt.Errorf("Error writing key content %w", err)) ctx.APIErrorInternal(fmt.Errorf("Error writing key content %w", err))
} }
} }

View File

@ -113,7 +113,7 @@ func (Action) CreateOrUpdateSecret(ctx *context.APIContext) {
} else if errors.Is(err, util.ErrNotExist) { } else if errors.Is(err, util.ErrNotExist) {
ctx.APIError(http.StatusNotFound, err) ctx.APIError(http.StatusNotFound, err)
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }
@ -160,7 +160,7 @@ func (Action) DeleteSecret(ctx *context.APIContext) {
} else if errors.Is(err, util.ErrNotExist) { } else if errors.Is(err, util.ErrNotExist) {
ctx.APIError(http.StatusNotFound, err) ctx.APIError(http.StatusNotFound, err)
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }
@ -223,7 +223,7 @@ func (Action) ListVariables(ctx *context.APIContext) {
ListOptions: utils.GetListOptions(ctx), ListOptions: utils.GetListOptions(ctx),
}) })
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
@ -275,7 +275,7 @@ func (Action) GetVariable(ctx *context.APIContext) {
if errors.Is(err, util.ErrNotExist) { if errors.Is(err, util.ErrNotExist) {
ctx.APIError(http.StatusNotFound, err) ctx.APIError(http.StatusNotFound, err)
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }
@ -326,7 +326,7 @@ func (Action) DeleteVariable(ctx *context.APIContext) {
} else if errors.Is(err, util.ErrNotExist) { } else if errors.Is(err, util.ErrNotExist) {
ctx.APIError(http.StatusNotFound, err) ctx.APIError(http.StatusNotFound, err)
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }
@ -378,7 +378,7 @@ func (Action) CreateVariable(ctx *context.APIContext) {
Name: variableName, Name: variableName,
}) })
if err != nil && !errors.Is(err, util.ErrNotExist) { if err != nil && !errors.Is(err, util.ErrNotExist) {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
if v != nil && v.ID > 0 { if v != nil && v.ID > 0 {
@ -390,7 +390,7 @@ func (Action) CreateVariable(ctx *context.APIContext) {
if errors.Is(err, util.ErrInvalidArgument) { if errors.Is(err, util.ErrInvalidArgument) {
ctx.APIError(http.StatusBadRequest, err) ctx.APIError(http.StatusBadRequest, err)
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }
@ -442,7 +442,7 @@ func (Action) UpdateVariable(ctx *context.APIContext) {
if errors.Is(err, util.ErrNotExist) { if errors.Is(err, util.ErrNotExist) {
ctx.APIError(http.StatusNotFound, err) ctx.APIError(http.StatusNotFound, err)
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }
@ -458,7 +458,7 @@ func (Action) UpdateVariable(ctx *context.APIContext) {
if errors.Is(err, util.ErrInvalidArgument) { if errors.Is(err, util.ErrInvalidArgument) {
ctx.APIError(http.StatusBadRequest, err) ctx.APIError(http.StatusBadRequest, err)
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }

View File

@ -45,7 +45,7 @@ func UpdateAvatar(ctx *context.APIContext) {
err = user_service.UploadAvatar(ctx, ctx.Org.Organization.AsUser(), content) err = user_service.UploadAvatar(ctx, ctx.Org.Organization.AsUser(), content)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
@ -72,7 +72,7 @@ func DeleteAvatar(ctx *context.APIContext) {
// "$ref": "#/responses/notFound" // "$ref": "#/responses/notFound"
err := user_service.DeleteAvatar(ctx, ctx.Org.Organization.AsUser()) err := user_service.DeleteAvatar(ctx, ctx.Org.Organization.AsUser())
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }

View File

@ -46,7 +46,7 @@ func ListLabels(ctx *context.APIContext) {
labels, err := issues_model.GetLabelsByOrgID(ctx, ctx.Org.Organization.ID, ctx.FormString("sort"), utils.GetListOptions(ctx)) labels, err := issues_model.GetLabelsByOrgID(ctx, ctx.Org.Organization.ID, ctx.FormString("sort"), utils.GetListOptions(ctx))
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
@ -103,7 +103,7 @@ func CreateLabel(ctx *context.APIContext) {
Description: form.Description, Description: form.Description,
} }
if err := issues_model.NewLabel(ctx, label); err != nil { if err := issues_model.NewLabel(ctx, label); err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
@ -149,7 +149,7 @@ func GetLabel(ctx *context.APIContext) {
if issues_model.IsErrOrgLabelNotExist(err) { if issues_model.IsErrOrgLabelNotExist(err) {
ctx.APIErrorNotFound() ctx.APIErrorNotFound()
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }
@ -195,7 +195,7 @@ func EditLabel(ctx *context.APIContext) {
if issues_model.IsErrOrgLabelNotExist(err) { if issues_model.IsErrOrgLabelNotExist(err) {
ctx.APIErrorNotFound() ctx.APIErrorNotFound()
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }
@ -219,7 +219,7 @@ func EditLabel(ctx *context.APIContext) {
} }
l.SetArchived(form.IsArchived != nil && *form.IsArchived) l.SetArchived(form.IsArchived != nil && *form.IsArchived)
if err := issues_model.UpdateLabel(ctx, l); err != nil { if err := issues_model.UpdateLabel(ctx, l); err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
@ -250,7 +250,7 @@ func DeleteLabel(ctx *context.APIContext) {
// "$ref": "#/responses/notFound" // "$ref": "#/responses/notFound"
if err := issues_model.DeleteLabel(ctx, ctx.Org.Organization.ID, ctx.PathParamInt64("id")); err != nil { if err := issues_model.DeleteLabel(ctx, ctx.Org.Organization.ID, ctx.PathParamInt64("id")); err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }

View File

@ -82,7 +82,7 @@ func ListMembers(ctx *context.APIContext) {
if ctx.Doer != nil { if ctx.Doer != nil {
isMember, err = ctx.Org.Organization.IsOrgMember(ctx, ctx.Doer.ID) isMember, err = ctx.Org.Organization.IsOrgMember(ctx, ctx.Doer.ID)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
} }
@ -150,12 +150,12 @@ func IsMember(ctx *context.APIContext) {
if ctx.Doer != nil { if ctx.Doer != nil {
userIsMember, err := ctx.Org.Organization.IsOrgMember(ctx, ctx.Doer.ID) userIsMember, err := ctx.Org.Organization.IsOrgMember(ctx, ctx.Doer.ID)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} else if userIsMember || ctx.Doer.IsAdmin { } else if userIsMember || ctx.Doer.IsAdmin {
userToCheckIsMember, err := ctx.Org.Organization.IsOrgMember(ctx, userToCheck.ID) userToCheckIsMember, err := ctx.Org.Organization.IsOrgMember(ctx, userToCheck.ID)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} else if userToCheckIsMember { } else if userToCheckIsMember {
ctx.Status(http.StatusNoContent) ctx.Status(http.StatusNoContent)
} else { } else {
@ -200,7 +200,7 @@ func IsPublicMember(ctx *context.APIContext) {
} }
is, err := organization.IsPublicMembership(ctx, ctx.Org.Organization.ID, userToCheck.ID) is, err := organization.IsPublicMembership(ctx, ctx.Org.Organization.ID, userToCheck.ID)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
if is { if is {
@ -246,7 +246,7 @@ func PublicizeMember(ctx *context.APIContext) {
} }
err := organization.ChangeOrgUserStatus(ctx, ctx.Org.Organization.ID, userToPublicize.ID, true) err := organization.ChangeOrgUserStatus(ctx, ctx.Org.Organization.ID, userToPublicize.ID, true)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
ctx.Status(http.StatusNoContent) ctx.Status(http.StatusNoContent)
@ -288,7 +288,7 @@ func ConcealMember(ctx *context.APIContext) {
} }
err := organization.ChangeOrgUserStatus(ctx, ctx.Org.Organization.ID, userToConceal.ID, false) err := organization.ChangeOrgUserStatus(ctx, ctx.Org.Organization.ID, userToConceal.ID, false)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
ctx.Status(http.StatusNoContent) ctx.Status(http.StatusNoContent)
@ -323,7 +323,7 @@ func DeleteMember(ctx *context.APIContext) {
return return
} }
if err := org_service.RemoveOrgUser(ctx, ctx.Org.Organization, member); err != nil { if err := org_service.RemoveOrgUser(ctx, ctx.Org.Organization, member); err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
ctx.Status(http.StatusNoContent) ctx.Status(http.StatusNoContent)
} }

View File

@ -35,7 +35,7 @@ func listUserOrgs(ctx *context.APIContext, u *user_model.User) {
} }
orgs, maxResults, err := db.FindAndCount[organization.Organization](ctx, opts) orgs, maxResults, err := db.FindAndCount[organization.Organization](ctx, opts)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
@ -145,7 +145,7 @@ func GetUserOrgsPermissions(ctx *context.APIContext) {
org := organization.OrgFromUser(o) org := organization.OrgFromUser(o)
authorizeLevel, err := org.GetOrgUserMaxAuthorizeLevel(ctx, ctx.ContextUser.ID) authorizeLevel, err := org.GetOrgUserMaxAuthorizeLevel(ctx, ctx.ContextUser.ID)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
@ -164,7 +164,7 @@ func GetUserOrgsPermissions(ctx *context.APIContext) {
op.CanCreateRepository, err = org.CanCreateOrgRepo(ctx, ctx.ContextUser.ID) op.CanCreateRepository, err = org.CanCreateOrgRepo(ctx, ctx.ContextUser.ID)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
@ -209,7 +209,7 @@ func GetAll(ctx *context.APIContext) {
Visible: vMode, Visible: vMode,
}) })
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
orgs := make([]*api.Organization, len(publicOrgs)) orgs := make([]*api.Organization, len(publicOrgs))
@ -273,7 +273,7 @@ func Create(ctx *context.APIContext) {
db.IsErrNamePatternNotAllowed(err) { db.IsErrNamePatternNotAllowed(err) {
ctx.APIError(http.StatusUnprocessableEntity, err) ctx.APIError(http.StatusUnprocessableEntity, err)
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }
@ -383,7 +383,7 @@ func Edit(ctx *context.APIContext) {
if form.Email != "" { if form.Email != "" {
if err := user_service.ReplacePrimaryEmailAddress(ctx, ctx.Org.Organization.AsUser(), form.Email); err != nil { if err := user_service.ReplacePrimaryEmailAddress(ctx, ctx.Org.Organization.AsUser(), form.Email); err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
} }
@ -397,7 +397,7 @@ func Edit(ctx *context.APIContext) {
RepoAdminChangeTeamAccess: optional.FromPtr(form.RepoAdminChangeTeamAccess), RepoAdminChangeTeamAccess: optional.FromPtr(form.RepoAdminChangeTeamAccess),
} }
if err := user_service.UpdateUser(ctx, ctx.Org.Organization.AsUser(), opts); err != nil { if err := user_service.UpdateUser(ctx, ctx.Org.Organization.AsUser(), opts); err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
@ -424,7 +424,7 @@ func Delete(ctx *context.APIContext) {
// "$ref": "#/responses/notFound" // "$ref": "#/responses/notFound"
if err := org.DeleteOrganization(ctx, ctx.Org.Organization, false); err != nil { if err := org.DeleteOrganization(ctx, ctx.Org.Organization, false); err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
ctx.Status(http.StatusNoContent) ctx.Status(http.StatusNoContent)
@ -469,7 +469,7 @@ func ListOrgActivityFeeds(ctx *context.APIContext) {
org := organization.OrgFromUser(ctx.ContextUser) org := organization.OrgFromUser(ctx.ContextUser)
isMember, err := org.IsOrgMember(ctx, ctx.Doer.ID) isMember, err := org.IsOrgMember(ctx, ctx.Doer.ID)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
includePrivate = isMember includePrivate = isMember
@ -488,7 +488,7 @@ func ListOrgActivityFeeds(ctx *context.APIContext) {
feeds, count, err := feed_service.GetFeeds(ctx, opts) feeds, count, err := feed_service.GetFeeds(ctx, opts)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
ctx.SetTotalCountHeader(count) ctx.SetTotalCountHeader(count)

View File

@ -59,13 +59,13 @@ func ListTeams(ctx *context.APIContext) {
OrgID: ctx.Org.Organization.ID, OrgID: ctx.Org.Organization.ID,
}) })
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
apiTeams, err := convert.ToTeams(ctx, teams, false) apiTeams, err := convert.ToTeams(ctx, teams, false)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
@ -98,13 +98,13 @@ func ListUserTeams(ctx *context.APIContext) {
UserID: ctx.Doer.ID, UserID: ctx.Doer.ID,
}) })
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
apiTeams, err := convert.ToTeams(ctx, teams, true) apiTeams, err := convert.ToTeams(ctx, teams, true)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
@ -233,7 +233,7 @@ func CreateTeam(ctx *context.APIContext) {
} else if len(form.Units) > 0 { } else if len(form.Units) > 0 {
attachTeamUnits(team, form.Units) attachTeamUnits(team, form.Units)
} else { } else {
ctx.APIError(http.StatusInternalServerError, errors.New("units permission should not be empty")) ctx.APIErrorInternal(errors.New("units permission should not be empty"))
return return
} }
} else { } else {
@ -244,7 +244,7 @@ func CreateTeam(ctx *context.APIContext) {
if organization.IsErrTeamAlreadyExist(err) { if organization.IsErrTeamAlreadyExist(err) {
ctx.APIError(http.StatusUnprocessableEntity, err) ctx.APIError(http.StatusUnprocessableEntity, err)
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }
@ -332,7 +332,7 @@ func EditTeam(ctx *context.APIContext) {
} }
if err := org_service.UpdateTeam(ctx, team, isAuthChanged, isIncludeAllChanged); err != nil { if err := org_service.UpdateTeam(ctx, team, isAuthChanged, isIncludeAllChanged); err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
@ -363,7 +363,7 @@ func DeleteTeam(ctx *context.APIContext) {
// "$ref": "#/responses/notFound" // "$ref": "#/responses/notFound"
if err := org_service.DeleteTeam(ctx, ctx.Org.Team); err != nil { if err := org_service.DeleteTeam(ctx, ctx.Org.Team); err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
ctx.Status(http.StatusNoContent) ctx.Status(http.StatusNoContent)
@ -399,7 +399,7 @@ func GetTeamMembers(ctx *context.APIContext) {
isMember, err := organization.IsOrganizationMember(ctx, ctx.Org.Team.OrgID, ctx.Doer.ID) isMember, err := organization.IsOrganizationMember(ctx, ctx.Org.Team.OrgID, ctx.Doer.ID)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} else if !isMember && !ctx.Doer.IsAdmin { } else if !isMember && !ctx.Doer.IsAdmin {
ctx.APIErrorNotFound() ctx.APIErrorNotFound()
@ -411,7 +411,7 @@ func GetTeamMembers(ctx *context.APIContext) {
TeamID: ctx.Org.Team.ID, TeamID: ctx.Org.Team.ID,
}) })
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
@ -456,7 +456,7 @@ func GetTeamMember(ctx *context.APIContext) {
teamID := ctx.PathParamInt64("teamid") teamID := ctx.PathParamInt64("teamid")
isTeamMember, err := organization.IsUserInTeams(ctx, u.ID, []int64{teamID}) isTeamMember, err := organization.IsUserInTeams(ctx, u.ID, []int64{teamID})
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} else if !isTeamMember { } else if !isTeamMember {
ctx.APIErrorNotFound() ctx.APIErrorNotFound()
@ -500,7 +500,7 @@ func AddTeamMember(ctx *context.APIContext) {
if errors.Is(err, user_model.ErrBlockedUser) { if errors.Is(err, user_model.ErrBlockedUser) {
ctx.APIError(http.StatusForbidden, err) ctx.APIError(http.StatusForbidden, err)
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }
@ -538,7 +538,7 @@ func RemoveTeamMember(ctx *context.APIContext) {
} }
if err := org_service.RemoveTeamMember(ctx, ctx.Org.Team, u); err != nil { if err := org_service.RemoveTeamMember(ctx, ctx.Org.Team, u); err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
ctx.Status(http.StatusNoContent) ctx.Status(http.StatusNoContent)
@ -578,14 +578,14 @@ func GetTeamRepos(ctx *context.APIContext) {
TeamID: team.ID, TeamID: team.ID,
}) })
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
repos := make([]*api.Repository, len(teamRepos)) repos := make([]*api.Repository, len(teamRepos))
for i, repo := range teamRepos { for i, repo := range teamRepos {
permission, err := access_model.GetUserRepoPermission(ctx, repo, ctx.Doer) permission, err := access_model.GetUserRepoPermission(ctx, repo, ctx.Doer)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
repos[i] = convert.ToRepo(ctx, repo, permission) repos[i] = convert.ToRepo(ctx, repo, permission)
@ -636,7 +636,7 @@ func GetTeamRepo(ctx *context.APIContext) {
permission, err := access_model.GetUserRepoPermission(ctx, repo, ctx.Doer) permission, err := access_model.GetUserRepoPermission(ctx, repo, ctx.Doer)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
@ -650,7 +650,7 @@ func getRepositoryByParams(ctx *context.APIContext) *repo_model.Repository {
if repo_model.IsErrRepoNotExist(err) { if repo_model.IsErrRepoNotExist(err) {
ctx.APIErrorNotFound() ctx.APIErrorNotFound()
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return nil return nil
} }
@ -694,14 +694,14 @@ func AddTeamRepository(ctx *context.APIContext) {
return return
} }
if access, err := access_model.AccessLevel(ctx, ctx.Doer, repo); err != nil { if access, err := access_model.AccessLevel(ctx, ctx.Doer, repo); err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} else if access < perm.AccessModeAdmin { } else if access < perm.AccessModeAdmin {
ctx.APIError(http.StatusForbidden, "Must have admin-level access to the repository") ctx.APIError(http.StatusForbidden, "Must have admin-level access to the repository")
return return
} }
if err := repo_service.TeamAddRepository(ctx, ctx.Org.Team, repo); err != nil { if err := repo_service.TeamAddRepository(ctx, ctx.Org.Team, repo); err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
ctx.Status(http.StatusNoContent) ctx.Status(http.StatusNoContent)
@ -746,14 +746,14 @@ func RemoveTeamRepository(ctx *context.APIContext) {
return return
} }
if access, err := access_model.AccessLevel(ctx, ctx.Doer, repo); err != nil { if access, err := access_model.AccessLevel(ctx, ctx.Doer, repo); err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} else if access < perm.AccessModeAdmin { } else if access < perm.AccessModeAdmin {
ctx.APIError(http.StatusForbidden, "Must have admin-level access to the repository") ctx.APIError(http.StatusForbidden, "Must have admin-level access to the repository")
return return
} }
if err := repo_service.RemoveRepositoryFromTeam(ctx, ctx.Org.Team, repo.ID); err != nil { if err := repo_service.RemoveRepositoryFromTeam(ctx, ctx.Org.Team, repo.ID); err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
ctx.Status(http.StatusNoContent) ctx.Status(http.StatusNoContent)
@ -885,7 +885,7 @@ func ListTeamActivityFeeds(ctx *context.APIContext) {
feeds, count, err := feed_service.GetFeeds(ctx, opts) feeds, count, err := feed_service.GetFeeds(ctx, opts)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
ctx.SetTotalCountHeader(count) ctx.SetTotalCountHeader(count)

View File

@ -67,13 +67,13 @@ func ListPackages(ctx *context.APIContext) {
Paginator: &listOptions, Paginator: &listOptions,
}) })
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
pds, err := packages.GetPackageDescriptors(ctx, pvs) pds, err := packages.GetPackageDescriptors(ctx, pvs)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
@ -81,7 +81,7 @@ func ListPackages(ctx *context.APIContext) {
for _, pd := range pds { for _, pd := range pds {
apiPackage, err := convert.ToPackage(ctx, pd, ctx.Doer) apiPackage, err := convert.ToPackage(ctx, pd, ctx.Doer)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
apiPackages = append(apiPackages, apiPackage) apiPackages = append(apiPackages, apiPackage)
@ -128,7 +128,7 @@ func GetPackage(ctx *context.APIContext) {
apiPackage, err := convert.ToPackage(ctx, ctx.Package.Descriptor, ctx.Doer) apiPackage, err := convert.ToPackage(ctx, ctx.Package.Descriptor, ctx.Doer)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
@ -169,7 +169,7 @@ func DeletePackage(ctx *context.APIContext) {
err := packages_service.RemovePackageVersion(ctx, ctx.Doer, ctx.Package.Descriptor.Version) err := packages_service.RemovePackageVersion(ctx, ctx.Doer, ctx.Package.Descriptor.Version)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
ctx.Status(http.StatusNoContent) ctx.Status(http.StatusNoContent)

View File

@ -143,7 +143,7 @@ func (Action) CreateOrUpdateSecret(ctx *context.APIContext) {
} else if errors.Is(err, util.ErrNotExist) { } else if errors.Is(err, util.ErrNotExist) {
ctx.APIError(http.StatusNotFound, err) ctx.APIError(http.StatusNotFound, err)
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }
@ -197,7 +197,7 @@ func (Action) DeleteSecret(ctx *context.APIContext) {
} else if errors.Is(err, util.ErrNotExist) { } else if errors.Is(err, util.ErrNotExist) {
ctx.APIError(http.StatusNotFound, err) ctx.APIError(http.StatusNotFound, err)
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }
@ -243,7 +243,7 @@ func (Action) GetVariable(ctx *context.APIContext) {
if errors.Is(err, util.ErrNotExist) { if errors.Is(err, util.ErrNotExist) {
ctx.APIError(http.StatusNotFound, err) ctx.APIError(http.StatusNotFound, err)
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }
@ -299,7 +299,7 @@ func (Action) DeleteVariable(ctx *context.APIContext) {
} else if errors.Is(err, util.ErrNotExist) { } else if errors.Is(err, util.ErrNotExist) {
ctx.APIError(http.StatusNotFound, err) ctx.APIError(http.StatusNotFound, err)
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }
@ -354,7 +354,7 @@ func (Action) CreateVariable(ctx *context.APIContext) {
Name: variableName, Name: variableName,
}) })
if err != nil && !errors.Is(err, util.ErrNotExist) { if err != nil && !errors.Is(err, util.ErrNotExist) {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
if v != nil && v.ID > 0 { if v != nil && v.ID > 0 {
@ -366,7 +366,7 @@ func (Action) CreateVariable(ctx *context.APIContext) {
if errors.Is(err, util.ErrInvalidArgument) { if errors.Is(err, util.ErrInvalidArgument) {
ctx.APIError(http.StatusBadRequest, err) ctx.APIError(http.StatusBadRequest, err)
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }
@ -421,7 +421,7 @@ func (Action) UpdateVariable(ctx *context.APIContext) {
if errors.Is(err, util.ErrNotExist) { if errors.Is(err, util.ErrNotExist) {
ctx.APIError(http.StatusNotFound, err) ctx.APIError(http.StatusNotFound, err)
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }
@ -437,7 +437,7 @@ func (Action) UpdateVariable(ctx *context.APIContext) {
if errors.Is(err, util.ErrInvalidArgument) { if errors.Is(err, util.ErrInvalidArgument) {
ctx.APIError(http.StatusBadRequest, err) ctx.APIError(http.StatusBadRequest, err)
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }
@ -484,7 +484,7 @@ func (Action) ListVariables(ctx *context.APIContext) {
ListOptions: utils.GetListOptions(ctx), ListOptions: utils.GetListOptions(ctx),
}) })
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
@ -581,7 +581,7 @@ func ListActionTasks(ctx *context.APIContext) {
RepoID: ctx.Repo.Repository.ID, RepoID: ctx.Repo.Repository.ID,
}) })
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
@ -592,7 +592,7 @@ func ListActionTasks(ctx *context.APIContext) {
for i := range tasks { for i := range tasks {
convertedTask, err := convert.ToActionTask(ctx, tasks[i]) convertedTask, err := convert.ToActionTask(ctx, tasks[i])
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
res.Entries[i] = convertedTask res.Entries[i] = convertedTask
@ -634,7 +634,7 @@ func ActionsListRepositoryWorkflows(ctx *context.APIContext) {
workflows, err := actions_service.ListActionWorkflows(ctx) workflows, err := actions_service.ListActionWorkflows(ctx)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
@ -683,7 +683,7 @@ func ActionsGetWorkflow(ctx *context.APIContext) {
if errors.Is(err, util.ErrNotExist) { if errors.Is(err, util.ErrNotExist) {
ctx.APIError(http.StatusNotFound, err) ctx.APIError(http.StatusNotFound, err)
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }
@ -731,7 +731,7 @@ func ActionsDisableWorkflow(ctx *context.APIContext) {
if errors.Is(err, util.ErrNotExist) { if errors.Is(err, util.ErrNotExist) {
ctx.APIError(http.StatusNotFound, err) ctx.APIError(http.StatusNotFound, err)
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }
@ -810,7 +810,7 @@ func ActionsDispatchWorkflow(ctx *context.APIContext) {
} else if errors.Is(err, util.ErrPermissionDenied) { } else if errors.Is(err, util.ErrPermissionDenied) {
ctx.APIError(http.StatusForbidden, err) ctx.APIError(http.StatusForbidden, err)
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }
@ -860,7 +860,7 @@ func ActionsEnableWorkflow(ctx *context.APIContext) {
if errors.Is(err, util.ErrNotExist) { if errors.Is(err, util.ErrNotExist) {
ctx.APIError(http.StatusNotFound, err) ctx.APIError(http.StatusNotFound, err)
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }
@ -1218,7 +1218,7 @@ func DownloadArtifactRaw(ctx *context.APIContext) {
if actions.IsArtifactV4(art) { if actions.IsArtifactV4(art) {
err := actions.DownloadArtifactV4(ctx.Base, art) err := actions.DownloadArtifactV4(ctx.Base, art)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
return return

View File

@ -50,7 +50,7 @@ func UpdateAvatar(ctx *context.APIContext) {
err = repo_service.UploadAvatar(ctx, ctx.Repo.Repository, content) err = repo_service.UploadAvatar(ctx, ctx.Repo.Repository, content)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
ctx.Status(http.StatusNoContent) ctx.Status(http.StatusNoContent)
@ -81,7 +81,7 @@ func DeleteAvatar(ctx *context.APIContext) {
// "$ref": "#/responses/notFound" // "$ref": "#/responses/notFound"
err := repo_service.DeleteAvatar(ctx, ctx.Repo.Repository) err := repo_service.DeleteAvatar(ctx, ctx.Repo.Repository)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
ctx.Status(http.StatusNoContent) ctx.Status(http.StatusNoContent)

View File

@ -65,26 +65,26 @@ func GetBranch(ctx *context.APIContext) {
if git.IsErrBranchNotExist(err) { if git.IsErrBranchNotExist(err) {
ctx.APIErrorNotFound(err) ctx.APIErrorNotFound(err)
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }
c, err := branch.GetCommit() c, err := branch.GetCommit()
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
branchProtection, err := git_model.GetFirstMatchProtectedBranchRule(ctx, ctx.Repo.Repository.ID, branchName) branchProtection, err := git_model.GetFirstMatchProtectedBranchRule(ctx, ctx.Repo.Repository.ID, branchName)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
br, err := convert.ToBranch(ctx, ctx.Repo.Repository, branch.Name, c, branchProtection, ctx.Doer, ctx.Repo.IsAdmin()) br, err := convert.ToBranch(ctx, ctx.Repo.Repository, branch.Name, c, branchProtection, ctx.Doer, ctx.Repo.IsAdmin())
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
@ -141,7 +141,7 @@ func DeleteBranch(ctx *context.APIContext) {
IsDeletedBranch: optional.Some(false), IsDeletedBranch: optional.Some(false),
}) })
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
if totalNumOfBranches == 0 { // sync branches immediately because non-empty repository should have at least 1 branch if totalNumOfBranches == 0 { // sync branches immediately because non-empty repository should have at least 1 branch
@ -161,7 +161,7 @@ func DeleteBranch(ctx *context.APIContext) {
case errors.Is(err, git_model.ErrBranchIsProtected): case errors.Is(err, git_model.ErrBranchIsProtected):
ctx.APIError(http.StatusForbidden, fmt.Errorf("branch protected")) ctx.APIError(http.StatusForbidden, fmt.Errorf("branch protected"))
default: default:
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }
@ -223,14 +223,14 @@ func CreateBranch(ctx *context.APIContext) {
if len(opt.OldRefName) > 0 { if len(opt.OldRefName) > 0 {
oldCommit, err = ctx.Repo.GitRepo.GetCommit(opt.OldRefName) oldCommit, err = ctx.Repo.GitRepo.GetCommit(opt.OldRefName)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
} else if len(opt.OldBranchName) > 0 { //nolint } else if len(opt.OldBranchName) > 0 { //nolint
if ctx.Repo.GitRepo.IsBranchExist(opt.OldBranchName) { //nolint if ctx.Repo.GitRepo.IsBranchExist(opt.OldBranchName) { //nolint
oldCommit, err = ctx.Repo.GitRepo.GetBranchCommit(opt.OldBranchName) //nolint oldCommit, err = ctx.Repo.GitRepo.GetBranchCommit(opt.OldBranchName) //nolint
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
} else { } else {
@ -240,7 +240,7 @@ func CreateBranch(ctx *context.APIContext) {
} else { } else {
oldCommit, err = ctx.Repo.GitRepo.GetBranchCommit(ctx.Repo.Repository.DefaultBranch) oldCommit, err = ctx.Repo.GitRepo.GetBranchCommit(ctx.Repo.Repository.DefaultBranch)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
} }
@ -256,32 +256,32 @@ func CreateBranch(ctx *context.APIContext) {
} else if git_model.IsErrBranchNameConflict(err) { } else if git_model.IsErrBranchNameConflict(err) {
ctx.APIError(http.StatusConflict, "The branch with the same name already exists.") ctx.APIError(http.StatusConflict, "The branch with the same name already exists.")
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }
branch, err := ctx.Repo.GitRepo.GetBranch(opt.BranchName) branch, err := ctx.Repo.GitRepo.GetBranch(opt.BranchName)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
commit, err := branch.GetCommit() commit, err := branch.GetCommit()
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
branchProtection, err := git_model.GetFirstMatchProtectedBranchRule(ctx, ctx.Repo.Repository.ID, branch.Name) branchProtection, err := git_model.GetFirstMatchProtectedBranchRule(ctx, ctx.Repo.Repository.ID, branch.Name)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
br, err := convert.ToBranch(ctx, ctx.Repo.Repository, branch.Name, commit, branchProtection, ctx.Doer, ctx.Repo.IsAdmin()) br, err := convert.ToBranch(ctx, ctx.Repo.Repository, branch.Name, commit, branchProtection, ctx.Doer, ctx.Repo.IsAdmin())
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
@ -325,7 +325,7 @@ func ListBranches(ctx *context.APIContext) {
if !ctx.Repo.Repository.IsEmpty { if !ctx.Repo.Repository.IsEmpty {
if ctx.Repo.GitRepo == nil { if ctx.Repo.GitRepo == nil {
ctx.APIError(http.StatusInternalServerError, nil) ctx.APIErrorInternal(nil)
return return
} }
@ -337,7 +337,7 @@ func ListBranches(ctx *context.APIContext) {
var err error var err error
totalNumOfBranches, err = db.Count[git_model.Branch](ctx, branchOpts) totalNumOfBranches, err = db.Count[git_model.Branch](ctx, branchOpts)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
if totalNumOfBranches == 0 { // sync branches immediately because non-empty repository should have at least 1 branch if totalNumOfBranches == 0 { // sync branches immediately because non-empty repository should have at least 1 branch
@ -350,13 +350,13 @@ func ListBranches(ctx *context.APIContext) {
rules, err := git_model.FindRepoProtectedBranchRules(ctx, ctx.Repo.Repository.ID) rules, err := git_model.FindRepoProtectedBranchRules(ctx, ctx.Repo.Repository.ID)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
branches, err := db.Find[git_model.Branch](ctx, branchOpts) branches, err := db.Find[git_model.Branch](ctx, branchOpts)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
@ -369,14 +369,14 @@ func ListBranches(ctx *context.APIContext) {
totalNumOfBranches-- totalNumOfBranches--
continue continue
} }
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
branchProtection := rules.GetFirstMatched(branches[i].Name) branchProtection := rules.GetFirstMatched(branches[i].Name)
apiBranch, err := convert.ToBranch(ctx, ctx.Repo.Repository, branches[i].Name, c, branchProtection, ctx.Doer, ctx.Repo.IsAdmin()) apiBranch, err := convert.ToBranch(ctx, ctx.Repo.Repository, branches[i].Name, c, branchProtection, ctx.Doer, ctx.Repo.IsAdmin())
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
apiBranches = append(apiBranches, apiBranch) apiBranches = append(apiBranches, apiBranch)
@ -450,7 +450,7 @@ func UpdateBranch(ctx *context.APIContext) {
case errors.Is(err, git_model.ErrBranchIsProtected): case errors.Is(err, git_model.ErrBranchIsProtected):
ctx.APIError(http.StatusForbidden, "Branch is protected by glob-based protection rules.") ctx.APIError(http.StatusForbidden, "Branch is protected by glob-based protection rules.")
default: default:
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }
@ -499,7 +499,7 @@ func GetBranchProtection(ctx *context.APIContext) {
bpName := ctx.PathParam("name") bpName := ctx.PathParam("name")
bp, err := git_model.GetProtectedBranchRuleByName(ctx, repo.ID, bpName) bp, err := git_model.GetProtectedBranchRuleByName(ctx, repo.ID, bpName)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
if bp == nil || bp.RepoID != repo.ID { if bp == nil || bp.RepoID != repo.ID {
@ -535,7 +535,7 @@ func ListBranchProtections(ctx *context.APIContext) {
repo := ctx.Repo.Repository repo := ctx.Repo.Repository
bps, err := git_model.FindRepoProtectedBranchRules(ctx, repo.ID) bps, err := git_model.FindRepoProtectedBranchRules(ctx, repo.ID)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
apiBps := make([]*api.BranchProtection, len(bps)) apiBps := make([]*api.BranchProtection, len(bps))
@ -602,7 +602,7 @@ func CreateBranchProtection(ctx *context.APIContext) {
protectBranch, err := git_model.GetProtectedBranchRuleByName(ctx, repo.ID, ruleName) protectBranch, err := git_model.GetProtectedBranchRuleByName(ctx, repo.ID, ruleName)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} else if protectBranch != nil { } else if protectBranch != nil {
ctx.APIError(http.StatusForbidden, "Branch protection already exist") ctx.APIError(http.StatusForbidden, "Branch protection already exist")
@ -620,7 +620,7 @@ func CreateBranchProtection(ctx *context.APIContext) {
ctx.APIError(http.StatusUnprocessableEntity, err) ctx.APIError(http.StatusUnprocessableEntity, err)
return return
} }
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
forcePushAllowlistUsers, err := user_model.GetUserIDsByNames(ctx, form.ForcePushAllowlistUsernames, false) forcePushAllowlistUsers, err := user_model.GetUserIDsByNames(ctx, form.ForcePushAllowlistUsernames, false)
@ -629,7 +629,7 @@ func CreateBranchProtection(ctx *context.APIContext) {
ctx.APIError(http.StatusUnprocessableEntity, err) ctx.APIError(http.StatusUnprocessableEntity, err)
return return
} }
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
mergeWhitelistUsers, err := user_model.GetUserIDsByNames(ctx, form.MergeWhitelistUsernames, false) mergeWhitelistUsers, err := user_model.GetUserIDsByNames(ctx, form.MergeWhitelistUsernames, false)
@ -638,7 +638,7 @@ func CreateBranchProtection(ctx *context.APIContext) {
ctx.APIError(http.StatusUnprocessableEntity, err) ctx.APIError(http.StatusUnprocessableEntity, err)
return return
} }
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
approvalsWhitelistUsers, err := user_model.GetUserIDsByNames(ctx, form.ApprovalsWhitelistUsernames, false) approvalsWhitelistUsers, err := user_model.GetUserIDsByNames(ctx, form.ApprovalsWhitelistUsernames, false)
@ -647,7 +647,7 @@ func CreateBranchProtection(ctx *context.APIContext) {
ctx.APIError(http.StatusUnprocessableEntity, err) ctx.APIError(http.StatusUnprocessableEntity, err)
return return
} }
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
var whitelistTeams, forcePushAllowlistTeams, mergeWhitelistTeams, approvalsWhitelistTeams []int64 var whitelistTeams, forcePushAllowlistTeams, mergeWhitelistTeams, approvalsWhitelistTeams []int64
@ -658,7 +658,7 @@ func CreateBranchProtection(ctx *context.APIContext) {
ctx.APIError(http.StatusUnprocessableEntity, err) ctx.APIError(http.StatusUnprocessableEntity, err)
return return
} }
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
forcePushAllowlistTeams, err = organization.GetTeamIDsByNames(ctx, repo.OwnerID, form.ForcePushAllowlistTeams, false) forcePushAllowlistTeams, err = organization.GetTeamIDsByNames(ctx, repo.OwnerID, form.ForcePushAllowlistTeams, false)
@ -667,7 +667,7 @@ func CreateBranchProtection(ctx *context.APIContext) {
ctx.APIError(http.StatusUnprocessableEntity, err) ctx.APIError(http.StatusUnprocessableEntity, err)
return return
} }
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
mergeWhitelistTeams, err = organization.GetTeamIDsByNames(ctx, repo.OwnerID, form.MergeWhitelistTeams, false) mergeWhitelistTeams, err = organization.GetTeamIDsByNames(ctx, repo.OwnerID, form.MergeWhitelistTeams, false)
@ -676,7 +676,7 @@ func CreateBranchProtection(ctx *context.APIContext) {
ctx.APIError(http.StatusUnprocessableEntity, err) ctx.APIError(http.StatusUnprocessableEntity, err)
return return
} }
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
approvalsWhitelistTeams, err = organization.GetTeamIDsByNames(ctx, repo.OwnerID, form.ApprovalsWhitelistTeams, false) approvalsWhitelistTeams, err = organization.GetTeamIDsByNames(ctx, repo.OwnerID, form.ApprovalsWhitelistTeams, false)
@ -685,7 +685,7 @@ func CreateBranchProtection(ctx *context.APIContext) {
ctx.APIError(http.StatusUnprocessableEntity, err) ctx.APIError(http.StatusUnprocessableEntity, err)
return return
} }
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
} }
@ -726,13 +726,13 @@ func CreateBranchProtection(ctx *context.APIContext) {
ApprovalsUserIDs: approvalsWhitelistUsers, ApprovalsUserIDs: approvalsWhitelistUsers,
ApprovalsTeamIDs: approvalsWhitelistTeams, ApprovalsTeamIDs: approvalsWhitelistTeams,
}); err != nil { }); err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
if isBranchExist { if isBranchExist {
if err := pull_service.CheckPRsForBaseBranch(ctx, ctx.Repo.Repository, ruleName); err != nil { if err := pull_service.CheckPRsForBaseBranch(ctx, ctx.Repo.Repository, ruleName); err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
} else { } else {
@ -740,20 +740,20 @@ func CreateBranchProtection(ctx *context.APIContext) {
if ctx.Repo.GitRepo == nil { if ctx.Repo.GitRepo == nil {
ctx.Repo.GitRepo, err = gitrepo.RepositoryFromRequestContextOrOpen(ctx, ctx.Repo.Repository) ctx.Repo.GitRepo, err = gitrepo.RepositoryFromRequestContextOrOpen(ctx, ctx.Repo.Repository)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
} }
// FIXME: since we only need to recheck files protected rules, we could improve this // FIXME: since we only need to recheck files protected rules, we could improve this
matchedBranches, err := git_model.FindAllMatchedBranches(ctx, ctx.Repo.Repository.ID, ruleName) matchedBranches, err := git_model.FindAllMatchedBranches(ctx, ctx.Repo.Repository.ID, ruleName)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
for _, branchName := range matchedBranches { for _, branchName := range matchedBranches {
if err = pull_service.CheckPRsForBaseBranch(ctx, ctx.Repo.Repository, branchName); err != nil { if err = pull_service.CheckPRsForBaseBranch(ctx, ctx.Repo.Repository, branchName); err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
} }
@ -763,11 +763,11 @@ func CreateBranchProtection(ctx *context.APIContext) {
// Reload from db to get all whitelists // Reload from db to get all whitelists
bp, err := git_model.GetProtectedBranchRuleByName(ctx, ctx.Repo.Repository.ID, ruleName) bp, err := git_model.GetProtectedBranchRuleByName(ctx, ctx.Repo.Repository.ID, ruleName)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
if bp == nil || bp.RepoID != ctx.Repo.Repository.ID { if bp == nil || bp.RepoID != ctx.Repo.Repository.ID {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
@ -817,7 +817,7 @@ func EditBranchProtection(ctx *context.APIContext) {
bpName := ctx.PathParam("name") bpName := ctx.PathParam("name")
protectBranch, err := git_model.GetProtectedBranchRuleByName(ctx, repo.ID, bpName) protectBranch, err := git_model.GetProtectedBranchRuleByName(ctx, repo.ID, bpName)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
if protectBranch == nil || protectBranch.RepoID != repo.ID { if protectBranch == nil || protectBranch.RepoID != repo.ID {
@ -935,7 +935,7 @@ func EditBranchProtection(ctx *context.APIContext) {
ctx.APIError(http.StatusUnprocessableEntity, err) ctx.APIError(http.StatusUnprocessableEntity, err)
return return
} }
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
} else { } else {
@ -948,7 +948,7 @@ func EditBranchProtection(ctx *context.APIContext) {
ctx.APIError(http.StatusUnprocessableEntity, err) ctx.APIError(http.StatusUnprocessableEntity, err)
return return
} }
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
} else { } else {
@ -961,7 +961,7 @@ func EditBranchProtection(ctx *context.APIContext) {
ctx.APIError(http.StatusUnprocessableEntity, err) ctx.APIError(http.StatusUnprocessableEntity, err)
return return
} }
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
} else { } else {
@ -974,7 +974,7 @@ func EditBranchProtection(ctx *context.APIContext) {
ctx.APIError(http.StatusUnprocessableEntity, err) ctx.APIError(http.StatusUnprocessableEntity, err)
return return
} }
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
} else { } else {
@ -990,7 +990,7 @@ func EditBranchProtection(ctx *context.APIContext) {
ctx.APIError(http.StatusUnprocessableEntity, err) ctx.APIError(http.StatusUnprocessableEntity, err)
return return
} }
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
} else { } else {
@ -1003,7 +1003,7 @@ func EditBranchProtection(ctx *context.APIContext) {
ctx.APIError(http.StatusUnprocessableEntity, err) ctx.APIError(http.StatusUnprocessableEntity, err)
return return
} }
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
} else { } else {
@ -1016,7 +1016,7 @@ func EditBranchProtection(ctx *context.APIContext) {
ctx.APIError(http.StatusUnprocessableEntity, err) ctx.APIError(http.StatusUnprocessableEntity, err)
return return
} }
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
} else { } else {
@ -1029,7 +1029,7 @@ func EditBranchProtection(ctx *context.APIContext) {
ctx.APIError(http.StatusUnprocessableEntity, err) ctx.APIError(http.StatusUnprocessableEntity, err)
return return
} }
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
} else { } else {
@ -1048,7 +1048,7 @@ func EditBranchProtection(ctx *context.APIContext) {
ApprovalsTeamIDs: approvalsWhitelistTeams, ApprovalsTeamIDs: approvalsWhitelistTeams,
}) })
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
@ -1060,7 +1060,7 @@ func EditBranchProtection(ctx *context.APIContext) {
if isBranchExist { if isBranchExist {
if err = pull_service.CheckPRsForBaseBranch(ctx, ctx.Repo.Repository, bpName); err != nil { if err = pull_service.CheckPRsForBaseBranch(ctx, ctx.Repo.Repository, bpName); err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
} else { } else {
@ -1068,7 +1068,7 @@ func EditBranchProtection(ctx *context.APIContext) {
if ctx.Repo.GitRepo == nil { if ctx.Repo.GitRepo == nil {
ctx.Repo.GitRepo, err = gitrepo.RepositoryFromRequestContextOrOpen(ctx, ctx.Repo.Repository) ctx.Repo.GitRepo, err = gitrepo.RepositoryFromRequestContextOrOpen(ctx, ctx.Repo.Repository)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
} }
@ -1076,13 +1076,13 @@ func EditBranchProtection(ctx *context.APIContext) {
// FIXME: since we only need to recheck files protected rules, we could improve this // FIXME: since we only need to recheck files protected rules, we could improve this
matchedBranches, err := git_model.FindAllMatchedBranches(ctx, ctx.Repo.Repository.ID, protectBranch.RuleName) matchedBranches, err := git_model.FindAllMatchedBranches(ctx, ctx.Repo.Repository.ID, protectBranch.RuleName)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
for _, branchName := range matchedBranches { for _, branchName := range matchedBranches {
if err = pull_service.CheckPRsForBaseBranch(ctx, ctx.Repo.Repository, branchName); err != nil { if err = pull_service.CheckPRsForBaseBranch(ctx, ctx.Repo.Repository, branchName); err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
} }
@ -1092,11 +1092,11 @@ func EditBranchProtection(ctx *context.APIContext) {
// Reload from db to ensure get all whitelists // Reload from db to ensure get all whitelists
bp, err := git_model.GetProtectedBranchRuleByName(ctx, repo.ID, bpName) bp, err := git_model.GetProtectedBranchRuleByName(ctx, repo.ID, bpName)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
if bp == nil || bp.RepoID != ctx.Repo.Repository.ID { if bp == nil || bp.RepoID != ctx.Repo.Repository.ID {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
@ -1136,7 +1136,7 @@ func DeleteBranchProtection(ctx *context.APIContext) {
bpName := ctx.PathParam("name") bpName := ctx.PathParam("name")
bp, err := git_model.GetProtectedBranchRuleByName(ctx, repo.ID, bpName) bp, err := git_model.GetProtectedBranchRuleByName(ctx, repo.ID, bpName)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
if bp == nil || bp.RepoID != repo.ID { if bp == nil || bp.RepoID != repo.ID {
@ -1145,7 +1145,7 @@ func DeleteBranchProtection(ctx *context.APIContext) {
} }
if err := git_model.DeleteProtectedBranch(ctx, ctx.Repo.Repository, bp.ID); err != nil { if err := git_model.DeleteProtectedBranch(ctx, ctx.Repo.Repository, bp.ID); err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
@ -1189,7 +1189,7 @@ func UpdateBranchProtectionPriories(ctx *context.APIContext) {
repo := ctx.Repo.Repository repo := ctx.Repo.Repository
if err := git_model.UpdateProtectBranchPriorities(ctx, repo, form.IDs); err != nil { if err := git_model.UpdateProtectBranchPriorities(ctx, repo, form.IDs); err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
@ -1234,7 +1234,7 @@ func MergeUpstream(ctx *context.APIContext) {
ctx.APIError(http.StatusNotFound, err) ctx.APIError(http.StatusNotFound, err)
return return
} }
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
ctx.JSON(http.StatusOK, &api.MergeUpstreamResponse{MergeStyle: mergeStyle}) ctx.JSON(http.StatusOK, &api.MergeUpstreamResponse{MergeStyle: mergeStyle})

View File

@ -59,7 +59,7 @@ func ListCollaborators(ctx *context.APIContext) {
RepoID: ctx.Repo.Repository.ID, RepoID: ctx.Repo.Repository.ID,
}) })
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
@ -108,13 +108,13 @@ func IsCollaborator(ctx *context.APIContext) {
if user_model.IsErrUserNotExist(err) { if user_model.IsErrUserNotExist(err) {
ctx.APIError(http.StatusUnprocessableEntity, err) ctx.APIError(http.StatusUnprocessableEntity, err)
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }
isColab, err := repo_model.IsCollaborator(ctx, ctx.Repo.Repository.ID, user.ID) isColab, err := repo_model.IsCollaborator(ctx, ctx.Repo.Repository.ID, user.ID)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
if isColab { if isColab {
@ -168,13 +168,13 @@ func AddOrUpdateCollaborator(ctx *context.APIContext) {
if user_model.IsErrUserNotExist(err) { if user_model.IsErrUserNotExist(err) {
ctx.APIError(http.StatusUnprocessableEntity, err) ctx.APIError(http.StatusUnprocessableEntity, err)
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }
if !collaborator.IsActive { if !collaborator.IsActive {
ctx.APIError(http.StatusInternalServerError, errors.New("collaborator's account is inactive")) ctx.APIErrorInternal(errors.New("collaborator's account is inactive"))
return return
} }
@ -187,7 +187,7 @@ func AddOrUpdateCollaborator(ctx *context.APIContext) {
if errors.Is(err, user_model.ErrBlockedUser) { if errors.Is(err, user_model.ErrBlockedUser) {
ctx.APIError(http.StatusForbidden, err) ctx.APIError(http.StatusForbidden, err)
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }
@ -231,13 +231,13 @@ func DeleteCollaborator(ctx *context.APIContext) {
if user_model.IsErrUserNotExist(err) { if user_model.IsErrUserNotExist(err) {
ctx.APIError(http.StatusUnprocessableEntity, err) ctx.APIError(http.StatusUnprocessableEntity, err)
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }
if err := repo_service.DeleteCollaboration(ctx, ctx.Repo.Repository, collaborator); err != nil { if err := repo_service.DeleteCollaboration(ctx, ctx.Repo.Repository, collaborator); err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
ctx.Status(http.StatusNoContent) ctx.Status(http.StatusNoContent)
@ -284,14 +284,14 @@ func GetRepoPermissions(ctx *context.APIContext) {
if user_model.IsErrUserNotExist(err) { if user_model.IsErrUserNotExist(err) {
ctx.APIError(http.StatusNotFound, err) ctx.APIError(http.StatusNotFound, err)
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }
permission, err := access_model.GetUserRepoPermission(ctx, ctx.Repo.Repository, collaborator) permission, err := access_model.GetUserRepoPermission(ctx, ctx.Repo.Repository, collaborator)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
@ -330,7 +330,7 @@ func GetReviewers(ctx *context.APIContext) {
reviewers, err := pull_service.GetReviewers(ctx, ctx.Repo.Repository, ctx.Doer.ID, 0) reviewers, err := pull_service.GetReviewers(ctx, ctx.Repo.Repository, ctx.Doer.ID, 0)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
ctx.JSON(http.StatusOK, convert.ToUsers(ctx, ctx.Doer, reviewers)) ctx.JSON(http.StatusOK, convert.ToUsers(ctx, ctx.Doer, reviewers))
@ -362,7 +362,7 @@ func GetAssignees(ctx *context.APIContext) {
assignees, err := repo_model.GetRepoAssignees(ctx, ctx.Repo.Repository) assignees, err := repo_model.GetRepoAssignees(ctx, ctx.Repo.Repository)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
ctx.JSON(http.StatusOK, convert.ToUsers(ctx, ctx.Doer, assignees)) ctx.JSON(http.StatusOK, convert.ToUsers(ctx, ctx.Doer, assignees))

View File

@ -79,13 +79,13 @@ func getCommit(ctx *context.APIContext, identifier string, toCommitOpts convert.
ctx.APIErrorNotFound(identifier) ctx.APIErrorNotFound(identifier)
return return
} }
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
json, err := convert.ToCommit(ctx, ctx.Repo.Repository, ctx.Repo.GitRepo, commit, nil, toCommitOpts) json, err := convert.ToCommit(ctx, ctx.Repo.Repository, ctx.Repo.GitRepo, commit, nil, toCommitOpts)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
ctx.JSON(http.StatusOK, json) ctx.JSON(http.StatusOK, json)
@ -182,20 +182,20 @@ func GetAllCommits(ctx *context.APIContext) {
// no sha supplied - use default branch // no sha supplied - use default branch
head, err := ctx.Repo.GitRepo.GetHEADBranch() head, err := ctx.Repo.GitRepo.GetHEADBranch()
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
baseCommit, err = ctx.Repo.GitRepo.GetBranchCommit(head.Name) baseCommit, err = ctx.Repo.GitRepo.GetBranchCommit(head.Name)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
} else { } else {
// get commit specified by sha // get commit specified by sha
baseCommit, err = ctx.Repo.GitRepo.GetCommit(sha) baseCommit, err = ctx.Repo.GitRepo.GetCommit(sha)
if err != nil { if err != nil {
ctx.NotFoundOrServerError("GetCommit", git.IsErrNotExist, err) ctx.NotFoundOrServerError(err)
return return
} }
} }
@ -207,14 +207,14 @@ func GetAllCommits(ctx *context.APIContext) {
Revision: []string{baseCommit.ID.String()}, Revision: []string{baseCommit.ID.String()},
}) })
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
// Query commits // Query commits
commits, err = baseCommit.CommitsByRange(listOptions.Page, listOptions.PageSize, not) commits, err = baseCommit.CommitsByRange(listOptions.Page, listOptions.PageSize, not)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
} else { } else {
@ -231,7 +231,7 @@ func GetAllCommits(ctx *context.APIContext) {
}) })
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} else if commitsCountTotal == 0 { } else if commitsCountTotal == 0 {
ctx.APIErrorNotFound("FileCommitsCount", nil) ctx.APIErrorNotFound("FileCommitsCount", nil)
@ -246,7 +246,7 @@ func GetAllCommits(ctx *context.APIContext) {
Page: listOptions.Page, Page: listOptions.Page,
}) })
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
} }
@ -259,7 +259,7 @@ func GetAllCommits(ctx *context.APIContext) {
// Create json struct // Create json struct
apiCommits[i], err = convert.ToCommit(ctx, ctx.Repo.Repository, ctx.Repo.GitRepo, commit, userCache, convert.ParseCommitOptions(ctx)) apiCommits[i], err = convert.ToCommit(ctx, ctx.Repo.Repository, ctx.Repo.GitRepo, commit, userCache, convert.ParseCommitOptions(ctx))
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
} }
@ -320,7 +320,7 @@ func DownloadCommitDiffOrPatch(ctx *context.APIContext) {
ctx.APIErrorNotFound(sha) ctx.APIErrorNotFound(sha)
return return
} }
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
} }
@ -359,17 +359,17 @@ func GetCommitPullRequest(ctx *context.APIContext) {
if issues_model.IsErrPullRequestNotExist(err) { if issues_model.IsErrPullRequestNotExist(err) {
ctx.APIError(http.StatusNotFound, err) ctx.APIError(http.StatusNotFound, err)
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }
if err = pr.LoadBaseRepo(ctx); err != nil { if err = pr.LoadBaseRepo(ctx); err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
if err = pr.LoadHeadRepo(ctx); err != nil { if err = pr.LoadHeadRepo(ctx); err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
ctx.JSON(http.StatusOK, convert.ToAPIPullRequest(ctx, pr, ctx.Doer)) ctx.JSON(http.StatusOK, convert.ToAPIPullRequest(ctx, pr, ctx.Doer))

View File

@ -47,7 +47,7 @@ func CompareDiff(ctx *context.APIContext) {
var err error var err error
ctx.Repo.GitRepo, err = gitrepo.RepositoryFromRequestContextOrOpen(ctx, ctx.Repo.Repository) ctx.Repo.GitRepo, err = gitrepo.RepositoryFromRequestContextOrOpen(ctx, ctx.Repo.Repository)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
} }

View File

@ -31,7 +31,7 @@ func DownloadArchive(ctx *context.APIContext) {
var err error var err error
ctx.Repo.GitRepo, err = gitrepo.RepositoryFromRequestContextOrOpen(ctx, ctx.Repo.Repository) ctx.Repo.GitRepo, err = gitrepo.RepositoryFromRequestContextOrOpen(ctx, ctx.Repo.Repository)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
} }

View File

@ -84,7 +84,7 @@ func GetRawFile(ctx *context.APIContext) {
ctx.RespHeader().Set(giteaObjectTypeHeader, string(files_service.GetObjectTypeFromTreeEntry(entry))) ctx.RespHeader().Set(giteaObjectTypeHeader, string(files_service.GetObjectTypeFromTreeEntry(entry)))
if err := common.ServeBlob(ctx.Base, ctx.Repo.TreePath, blob, lastModified); err != nil { if err := common.ServeBlob(ctx.Base, ctx.Repo.TreePath, blob, lastModified); err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
} }
@ -231,7 +231,7 @@ func getBlobForEntry(ctx *context.APIContext) (blob *git.Blob, entry *git.TreeEn
if git.IsErrNotExist(err) { if git.IsErrNotExist(err) {
ctx.APIErrorNotFound() ctx.APIErrorNotFound()
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return nil, nil, nil return nil, nil, nil
} }
@ -243,7 +243,7 @@ func getBlobForEntry(ctx *context.APIContext) (blob *git.Blob, entry *git.TreeEn
latestCommit, err := ctx.Repo.GitRepo.GetTreePathLatestCommit(ctx.Repo.Commit.ID.String(), ctx.Repo.TreePath) latestCommit, err := ctx.Repo.GitRepo.GetTreePathLatestCommit(ctx.Repo.Commit.ID.String(), ctx.Repo.TreePath)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return nil, nil, nil return nil, nil, nil
} }
when := &latestCommit.Committer.When when := &latestCommit.Committer.When
@ -284,7 +284,7 @@ func GetArchive(ctx *context.APIContext) {
var err error var err error
ctx.Repo.GitRepo, err = gitrepo.RepositoryFromRequestContextOrOpen(ctx, ctx.Repo.Repository) ctx.Repo.GitRepo, err = gitrepo.RepositoryFromRequestContextOrOpen(ctx, ctx.Repo.Repository)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
} }
@ -389,7 +389,7 @@ func GetEditorconfig(ctx *context.APIContext) {
if git.IsErrNotExist(err) { if git.IsErrNotExist(err) {
ctx.APIErrorNotFound(err) ctx.APIErrorNotFound(err)
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }
@ -736,7 +736,7 @@ func handleCreateOrUpdateFileError(ctx *context.APIContext, err error) {
return return
} }
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
// Called from both CreateFile or UpdateFile to handle both // Called from both CreateFile or UpdateFile to handle both
@ -887,7 +887,7 @@ func DeleteFile(ctx *context.APIContext) {
ctx.APIError(http.StatusForbidden, err) ctx.APIError(http.StatusForbidden, err)
return return
} }
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} else { } else {
fileResponse := files_service.GetFileResponseFromFilesResponse(filesResponse, 0) fileResponse := files_service.GetFileResponseFromFilesResponse(filesResponse, 0)
ctx.JSON(http.StatusOK, fileResponse) // FIXME on APIv2: return http.StatusNoContent ctx.JSON(http.StatusOK, fileResponse) // FIXME on APIv2: return http.StatusNoContent
@ -929,7 +929,7 @@ func GetContents(ctx *context.APIContext) {
// "$ref": "#/responses/notFound" // "$ref": "#/responses/notFound"
if !canReadFiles(ctx.Repo) { if !canReadFiles(ctx.Repo) {
ctx.APIError(http.StatusInternalServerError, repo_model.ErrUserDoesNotHaveAccessToRepo{ ctx.APIErrorInternal(repo_model.ErrUserDoesNotHaveAccessToRepo{
UserID: ctx.Doer.ID, UserID: ctx.Doer.ID,
RepoName: ctx.Repo.Repository.LowerName, RepoName: ctx.Repo.Repository.LowerName,
}) })
@ -944,7 +944,7 @@ func GetContents(ctx *context.APIContext) {
ctx.APIErrorNotFound("GetContentsOrList", err) ctx.APIErrorNotFound("GetContentsOrList", err)
return return
} }
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} else { } else {
ctx.JSON(http.StatusOK, fileList) ctx.JSON(http.StatusOK, fileList)
} }

View File

@ -57,15 +57,15 @@ func ListForks(ctx *context.APIContext) {
forks, total, err := repo_service.FindForks(ctx, ctx.Repo.Repository, ctx.Doer, utils.GetListOptions(ctx)) forks, total, err := repo_service.FindForks(ctx, ctx.Repo.Repository, ctx.Doer, utils.GetListOptions(ctx))
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
if err := repo_model.RepositoryList(forks).LoadOwners(ctx); err != nil { if err := repo_model.RepositoryList(forks).LoadOwners(ctx); err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
if err := repo_model.RepositoryList(forks).LoadUnits(ctx); err != nil { if err := repo_model.RepositoryList(forks).LoadUnits(ctx); err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
@ -73,7 +73,7 @@ func ListForks(ctx *context.APIContext) {
for i, fork := range forks { for i, fork := range forks {
permission, err := access_model.GetUserRepoPermission(ctx, fork, ctx.Doer) permission, err := access_model.GetUserRepoPermission(ctx, fork, ctx.Doer)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
apiForks[i] = convert.ToRepo(ctx, fork, permission) apiForks[i] = convert.ToRepo(ctx, fork, permission)
@ -128,14 +128,14 @@ func CreateFork(ctx *context.APIContext) {
if organization.IsErrOrgNotExist(err) { if organization.IsErrOrgNotExist(err) {
ctx.APIError(http.StatusUnprocessableEntity, err) ctx.APIError(http.StatusUnprocessableEntity, err)
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }
if !ctx.Doer.IsAdmin { if !ctx.Doer.IsAdmin {
isMember, err := org.IsOrgMember(ctx, ctx.Doer.ID) isMember, err := org.IsOrgMember(ctx, ctx.Doer.ID)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} else if !isMember { } else if !isMember {
ctx.APIError(http.StatusForbidden, fmt.Sprintf("User is no Member of Organisation '%s'", org.Name)) ctx.APIError(http.StatusForbidden, fmt.Sprintf("User is no Member of Organisation '%s'", org.Name))
@ -163,7 +163,7 @@ func CreateFork(ctx *context.APIContext) {
} else if errors.Is(err, user_model.ErrBlockedUser) { } else if errors.Is(err, user_model.ErrBlockedUser) {
ctx.APIError(http.StatusForbidden, err) ctx.APIError(http.StatusForbidden, err)
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }

View File

@ -40,7 +40,7 @@ func ListGitHooks(ctx *context.APIContext) {
hooks, err := ctx.Repo.GitRepo.Hooks() hooks, err := ctx.Repo.GitRepo.Hooks()
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
@ -86,7 +86,7 @@ func GetGitHook(ctx *context.APIContext) {
if errors.Is(err, git.ErrNotValidHook) { if errors.Is(err, git.ErrNotValidHook) {
ctx.APIErrorNotFound() ctx.APIErrorNotFound()
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }
@ -133,14 +133,14 @@ func EditGitHook(ctx *context.APIContext) {
if errors.Is(err, git.ErrNotValidHook) { if errors.Is(err, git.ErrNotValidHook) {
ctx.APIErrorNotFound() ctx.APIErrorNotFound()
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }
hook.Content = form.Content hook.Content = form.Content
if err = hook.Update(); err != nil { if err = hook.Update(); err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
@ -182,14 +182,14 @@ func DeleteGitHook(ctx *context.APIContext) {
if errors.Is(err, git.ErrNotValidHook) { if errors.Is(err, git.ErrNotValidHook) {
ctx.APIErrorNotFound() ctx.APIErrorNotFound()
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }
hook.Content = "" hook.Content = ""
if err = hook.Update(); err != nil { if err = hook.Update(); err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }

View File

@ -78,7 +78,7 @@ func GetGitRefs(ctx *context.APIContext) {
func getGitRefsInternal(ctx *context.APIContext, filter string) { func getGitRefsInternal(ctx *context.APIContext, filter string) {
refs, lastMethodName, err := utils.GetGitRefs(ctx, filter) refs, lastMethodName, err := utils.GetGitRefs(ctx, filter)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, fmt.Errorf("%s: %w", lastMethodName, err)) ctx.APIErrorInternal(fmt.Errorf("%s: %w", lastMethodName, err))
return return
} }

View File

@ -189,7 +189,7 @@ func TestHook(ctx *context.APIContext) {
Pusher: convert.ToUserWithAccessMode(ctx, ctx.Doer, perm.AccessModeNone), Pusher: convert.ToUserWithAccessMode(ctx, ctx.Doer, perm.AccessModeNone),
Sender: convert.ToUserWithAccessMode(ctx, ctx.Doer, perm.AccessModeNone), Sender: convert.ToUserWithAccessMode(ctx, ctx.Doer, perm.AccessModeNone),
}); err != nil { }); err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
@ -300,7 +300,7 @@ func DeleteHook(ctx *context.APIContext) {
if webhook.IsErrWebhookNotExist(err) { if webhook.IsErrWebhookNotExist(err) {
ctx.APIErrorNotFound() ctx.APIErrorNotFound()
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }

View File

@ -172,7 +172,7 @@ func SearchIssues(ctx *context.APIContext) {
if user_model.IsErrUserNotExist(err) { if user_model.IsErrUserNotExist(err) {
ctx.APIError(http.StatusBadRequest, err) ctx.APIError(http.StatusBadRequest, err)
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }
@ -191,7 +191,7 @@ func SearchIssues(ctx *context.APIContext) {
if organization.IsErrTeamNotExist(err) { if organization.IsErrTeamNotExist(err) {
ctx.APIError(http.StatusBadRequest, err) ctx.APIError(http.StatusBadRequest, err)
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }
@ -204,7 +204,7 @@ func SearchIssues(ctx *context.APIContext) {
} }
repoIDs, _, err = repo_model.SearchRepositoryIDs(ctx, opts) repoIDs, _, err = repo_model.SearchRepositoryIDs(ctx, opts)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
if len(repoIDs) == 0 { if len(repoIDs) == 0 {
@ -237,7 +237,7 @@ func SearchIssues(ctx *context.APIContext) {
} }
includedAnyLabels, err = issues_model.GetLabelIDsByNames(ctx, includedLabelNames) includedAnyLabels, err = issues_model.GetLabelIDsByNames(ctx, includedLabelNames)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
} }
@ -251,7 +251,7 @@ func SearchIssues(ctx *context.APIContext) {
} }
includedMilestones, err = issues_model.GetMilestoneIDsByNames(ctx, includedMilestoneNames) includedMilestones, err = issues_model.GetMilestoneIDsByNames(ctx, includedMilestoneNames)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
} }
@ -312,12 +312,12 @@ func SearchIssues(ctx *context.APIContext) {
ids, total, err := issue_indexer.SearchIssues(ctx, searchOpt) ids, total, err := issue_indexer.SearchIssues(ctx, searchOpt)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
issues, err := issues_model.GetIssuesByIDs(ctx, ids, true) issues, err := issues_model.GetIssuesByIDs(ctx, ids, true)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
@ -428,7 +428,7 @@ func ListIssues(ctx *context.APIContext) {
if splitted := strings.Split(ctx.FormString("labels"), ","); len(splitted) > 0 { if splitted := strings.Split(ctx.FormString("labels"), ","); len(splitted) > 0 {
labelIDs, err = issues_model.GetLabelIDsInRepoByNames(ctx, ctx.Repo.Repository.ID, splitted) labelIDs, err = issues_model.GetLabelIDsInRepoByNames(ctx, ctx.Repo.Repository.ID, splitted)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
} }
@ -444,7 +444,7 @@ func ListIssues(ctx *context.APIContext) {
continue continue
} }
if !issues_model.IsErrMilestoneNotExist(err) { if !issues_model.IsErrMilestoneNotExist(err) {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
id, err := strconv.ParseInt(part[i], 10, 64) id, err := strconv.ParseInt(part[i], 10, 64)
@ -459,7 +459,7 @@ func ListIssues(ctx *context.APIContext) {
if issues_model.IsErrMilestoneNotExist(err) { if issues_model.IsErrMilestoneNotExist(err) {
continue continue
} }
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
} }
@ -549,12 +549,12 @@ func ListIssues(ctx *context.APIContext) {
ids, total, err := issue_indexer.SearchIssues(ctx, searchOpt) ids, total, err := issue_indexer.SearchIssues(ctx, searchOpt)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
issues, err := issues_model.GetIssuesByIDs(ctx, ids, true) issues, err := issues_model.GetIssuesByIDs(ctx, ids, true)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
@ -618,7 +618,7 @@ func GetIssue(ctx *context.APIContext) {
if issues_model.IsErrIssueNotExist(err) { if issues_model.IsErrIssueNotExist(err) {
ctx.APIErrorNotFound() ctx.APIErrorNotFound()
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }
@ -693,7 +693,7 @@ func CreateIssue(ctx *context.APIContext) {
if user_model.IsErrUserNotExist(err) { if user_model.IsErrUserNotExist(err) {
ctx.APIError(http.StatusUnprocessableEntity, fmt.Sprintf("Assignee does not exist: [name: %s]", err)) ctx.APIError(http.StatusUnprocessableEntity, fmt.Sprintf("Assignee does not exist: [name: %s]", err))
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }
@ -702,13 +702,13 @@ func CreateIssue(ctx *context.APIContext) {
for _, aID := range assigneeIDs { for _, aID := range assigneeIDs {
assignee, err := user_model.GetUserByID(ctx, aID) assignee, err := user_model.GetUserByID(ctx, aID)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
valid, err := access_model.CanBeAssigned(ctx, assignee, ctx.Repo.Repository, false) valid, err := access_model.CanBeAssigned(ctx, assignee, ctx.Repo.Repository, false)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
if !valid { if !valid {
@ -727,7 +727,7 @@ func CreateIssue(ctx *context.APIContext) {
} else if errors.Is(err, user_model.ErrBlockedUser) { } else if errors.Is(err, user_model.ErrBlockedUser) {
ctx.APIError(http.StatusForbidden, err) ctx.APIError(http.StatusForbidden, err)
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }
@ -738,7 +738,7 @@ func CreateIssue(ctx *context.APIContext) {
ctx.APIError(http.StatusPreconditionFailed, "cannot close this issue because it still has open dependencies") ctx.APIError(http.StatusPreconditionFailed, "cannot close this issue because it still has open dependencies")
return return
} }
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
} }
@ -746,7 +746,7 @@ func CreateIssue(ctx *context.APIContext) {
// Refetch from database to assign some automatic values // Refetch from database to assign some automatic values
issue, err = issues_model.GetIssueByID(ctx, issue.ID) issue, err = issues_model.GetIssueByID(ctx, issue.ID)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
ctx.JSON(http.StatusCreated, convert.ToAPIIssue(ctx, ctx.Doer, issue)) ctx.JSON(http.StatusCreated, convert.ToAPIIssue(ctx, ctx.Doer, issue))
@ -798,7 +798,7 @@ func EditIssue(ctx *context.APIContext) {
if issues_model.IsErrIssueNotExist(err) { if issues_model.IsErrIssueNotExist(err) {
ctx.APIErrorNotFound() ctx.APIErrorNotFound()
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }
@ -807,7 +807,7 @@ func EditIssue(ctx *context.APIContext) {
err = issue.LoadAttributes(ctx) err = issue.LoadAttributes(ctx)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
@ -819,7 +819,7 @@ func EditIssue(ctx *context.APIContext) {
if len(form.Title) > 0 { if len(form.Title) > 0 {
err = issue_service.ChangeTitle(ctx, issue, ctx.Doer, form.Title) err = issue_service.ChangeTitle(ctx, issue, ctx.Doer, form.Title)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
} }
@ -831,14 +831,14 @@ func EditIssue(ctx *context.APIContext) {
return return
} }
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
} }
if form.Ref != nil { if form.Ref != nil {
err = issue_service.ChangeIssueRef(ctx, issue, ctx.Doer, *form.Ref) err = issue_service.ChangeIssueRef(ctx, issue, ctx.Doer, *form.Ref)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
} }
@ -860,7 +860,7 @@ func EditIssue(ctx *context.APIContext) {
} }
if err := issues_model.UpdateIssueDeadline(ctx, issue, deadlineUnix, ctx.Doer); err != nil { if err := issues_model.UpdateIssueDeadline(ctx, issue, deadlineUnix, ctx.Doer); err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
issue.DeadlineUnix = deadlineUnix issue.DeadlineUnix = deadlineUnix
@ -885,7 +885,7 @@ func EditIssue(ctx *context.APIContext) {
if errors.Is(err, user_model.ErrBlockedUser) { if errors.Is(err, user_model.ErrBlockedUser) {
ctx.APIError(http.StatusForbidden, err) ctx.APIError(http.StatusForbidden, err)
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }
@ -896,14 +896,14 @@ func EditIssue(ctx *context.APIContext) {
oldMilestoneID := issue.MilestoneID oldMilestoneID := issue.MilestoneID
issue.MilestoneID = *form.Milestone issue.MilestoneID = *form.Milestone
if err = issue_service.ChangeMilestoneAssign(ctx, issue, ctx.Doer, oldMilestoneID); err != nil { if err = issue_service.ChangeMilestoneAssign(ctx, issue, ctx.Doer, oldMilestoneID); err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
} }
if form.State != nil { if form.State != nil {
if issue.IsPull { if issue.IsPull {
if err := issue.LoadPullRequest(ctx); err != nil { if err := issue.LoadPullRequest(ctx); err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
if issue.PullRequest.HasMerged { if issue.PullRequest.HasMerged {
@ -965,13 +965,13 @@ func DeleteIssue(ctx *context.APIContext) {
if issues_model.IsErrIssueNotExist(err) { if issues_model.IsErrIssueNotExist(err) {
ctx.APIErrorNotFound(err) ctx.APIErrorNotFound(err)
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }
if err = issue_service.DeleteIssue(ctx, ctx.Doer, ctx.Repo.GitRepo, issue); err != nil { if err = issue_service.DeleteIssue(ctx, ctx.Doer, ctx.Repo.GitRepo, issue); err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
@ -1021,7 +1021,7 @@ func UpdateIssueDeadline(ctx *context.APIContext) {
if issues_model.IsErrIssueNotExist(err) { if issues_model.IsErrIssueNotExist(err) {
ctx.APIErrorNotFound() ctx.APIErrorNotFound()
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }
@ -1033,7 +1033,7 @@ func UpdateIssueDeadline(ctx *context.APIContext) {
deadlineUnix, _ := common.ParseAPIDeadlineToEndOfDay(form.Deadline) deadlineUnix, _ := common.ParseAPIDeadlineToEndOfDay(form.Deadline)
if err := issues_model.UpdateIssueDeadline(ctx, issue, deadlineUnix, ctx.Doer); err != nil { if err := issues_model.UpdateIssueDeadline(ctx, issue, deadlineUnix, ctx.Doer); err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
@ -1052,12 +1052,12 @@ func closeOrReopenIssue(ctx *context.APIContext, issue *issues_model.Issue, stat
ctx.APIError(http.StatusPreconditionFailed, "cannot close this issue or pull request because it still has open dependencies") ctx.APIError(http.StatusPreconditionFailed, "cannot close this issue or pull request because it still has open dependencies")
return return
} }
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
} else if state == api.StateOpen && issue.IsClosed { } else if state == api.StateOpen && issue.IsClosed {
if err := issue_service.ReopenIssue(ctx, issue, ctx.Doer, ""); err != nil { if err := issue_service.ReopenIssue(ctx, issue, ctx.Doer, ""); err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
} }

View File

@ -104,7 +104,7 @@ func ListIssueAttachments(ctx *context.APIContext) {
} }
if err := issue.LoadAttributes(ctx); err != nil { if err := issue.LoadAttributes(ctx); err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
@ -171,7 +171,7 @@ func CreateIssueAttachment(ctx *context.APIContext) {
// Get uploaded file from request // Get uploaded file from request
file, header, err := ctx.Req.FormFile("attachment") file, header, err := ctx.Req.FormFile("attachment")
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
defer file.Close() defer file.Close()
@ -191,7 +191,7 @@ func CreateIssueAttachment(ctx *context.APIContext) {
if upload.IsErrFileTypeForbidden(err) { if upload.IsErrFileTypeForbidden(err) {
ctx.APIError(http.StatusUnprocessableEntity, err) ctx.APIError(http.StatusUnprocessableEntity, err)
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }
@ -199,7 +199,7 @@ func CreateIssueAttachment(ctx *context.APIContext) {
issue.Attachments = append(issue.Attachments, attachment) issue.Attachments = append(issue.Attachments, attachment)
if err := issue_service.ChangeContent(ctx, issue, ctx.Doer, issue.Content, issue.ContentVersion); err != nil { if err := issue_service.ChangeContent(ctx, issue, ctx.Doer, issue.Content, issue.ContentVersion); err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
@ -268,7 +268,7 @@ func EditIssueAttachment(ctx *context.APIContext) {
ctx.APIError(http.StatusUnprocessableEntity, err) ctx.APIError(http.StatusUnprocessableEntity, err)
return return
} }
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
@ -319,7 +319,7 @@ func DeleteIssueAttachment(ctx *context.APIContext) {
} }
if err := repo_model.DeleteAttachment(ctx, attachment, true); err != nil { if err := repo_model.DeleteAttachment(ctx, attachment, true); err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
@ -329,7 +329,7 @@ func DeleteIssueAttachment(ctx *context.APIContext) {
func getIssueFromContext(ctx *context.APIContext) *issues_model.Issue { func getIssueFromContext(ctx *context.APIContext) *issues_model.Issue {
issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index")) issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
if err != nil { if err != nil {
ctx.NotFoundOrServerError("GetIssueByIndex", issues_model.IsErrIssueNotExist, err) ctx.NotFoundOrServerError(err)
return nil return nil
} }
@ -354,7 +354,7 @@ func getIssueAttachmentSafeWrite(ctx *context.APIContext) *repo_model.Attachment
func getIssueAttachmentSafeRead(ctx *context.APIContext, issue *issues_model.Issue) *repo_model.Attachment { func getIssueAttachmentSafeRead(ctx *context.APIContext, issue *issues_model.Issue) *repo_model.Attachment {
attachment, err := repo_model.GetAttachmentByID(ctx, ctx.PathParamInt64("attachment_id")) attachment, err := repo_model.GetAttachmentByID(ctx, ctx.PathParamInt64("attachment_id"))
if err != nil { if err != nil {
ctx.NotFoundOrServerError("GetAttachmentByID", repo_model.IsErrAttachmentNotExist, err) ctx.NotFoundOrServerError(err)
return nil return nil
} }
if !attachmentBelongsToRepoOrIssue(ctx, attachment, issue) { if !attachmentBelongsToRepoOrIssue(ctx, attachment, issue) {

View File

@ -70,7 +70,7 @@ func ListIssueComments(ctx *context.APIContext) {
} }
issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index")) issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
if !ctx.Repo.CanReadIssuesOrPulls(issue.IsPull) { if !ctx.Repo.CanReadIssuesOrPulls(issue.IsPull) {
@ -89,7 +89,7 @@ func ListIssueComments(ctx *context.APIContext) {
comments, err := issues_model.FindComments(ctx, opts) comments, err := issues_model.FindComments(ctx, opts)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
@ -100,12 +100,12 @@ func ListIssueComments(ctx *context.APIContext) {
} }
if err := comments.LoadPosters(ctx); err != nil { if err := comments.LoadPosters(ctx); err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
if err := comments.LoadAttachments(ctx); err != nil { if err := comments.LoadAttachments(ctx); err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
@ -174,7 +174,7 @@ func ListIssueCommentsAndTimeline(ctx *context.APIContext) {
} }
issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index")) issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
issue.Repo = ctx.Repo.Repository issue.Repo = ctx.Repo.Repository
@ -189,12 +189,12 @@ func ListIssueCommentsAndTimeline(ctx *context.APIContext) {
comments, err := issues_model.FindComments(ctx, opts) comments, err := issues_model.FindComments(ctx, opts)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
if err := comments.LoadPosters(ctx); err != nil { if err := comments.LoadPosters(ctx); err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
@ -303,7 +303,7 @@ func ListRepoIssueComments(ctx *context.APIContext) {
comments, err := issues_model.FindComments(ctx, opts) comments, err := issues_model.FindComments(ctx, opts)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
@ -314,21 +314,21 @@ func ListRepoIssueComments(ctx *context.APIContext) {
} }
if err = comments.LoadPosters(ctx); err != nil { if err = comments.LoadPosters(ctx); err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
apiComments := make([]*api.Comment, len(comments)) apiComments := make([]*api.Comment, len(comments))
if err := comments.LoadIssues(ctx); err != nil { if err := comments.LoadIssues(ctx); err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
if err := comments.LoadAttachments(ctx); err != nil { if err := comments.LoadAttachments(ctx); err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
if _, err := comments.Issues().LoadRepositories(ctx); err != nil { if _, err := comments.Issues().LoadRepositories(ctx); err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
for i := range comments { for i := range comments {
@ -382,7 +382,7 @@ func CreateIssueComment(ctx *context.APIContext) {
form := web.GetForm(ctx).(*api.CreateIssueCommentOption) form := web.GetForm(ctx).(*api.CreateIssueCommentOption)
issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index")) issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
@ -401,7 +401,7 @@ func CreateIssueComment(ctx *context.APIContext) {
if errors.Is(err, user_model.ErrBlockedUser) { if errors.Is(err, user_model.ErrBlockedUser) {
ctx.APIError(http.StatusForbidden, err) ctx.APIError(http.StatusForbidden, err)
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }
@ -450,7 +450,7 @@ func GetIssueComment(ctx *context.APIContext) {
if issues_model.IsErrCommentNotExist(err) { if issues_model.IsErrCommentNotExist(err) {
ctx.APIErrorNotFound(err) ctx.APIErrorNotFound(err)
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }
@ -475,7 +475,7 @@ func GetIssueComment(ctx *context.APIContext) {
} }
if err := comment.LoadPoster(ctx); err != nil { if err := comment.LoadPoster(ctx); err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
@ -584,13 +584,13 @@ func editIssueComment(ctx *context.APIContext, form api.EditIssueCommentOption)
if issues_model.IsErrCommentNotExist(err) { if issues_model.IsErrCommentNotExist(err) {
ctx.APIErrorNotFound(err) ctx.APIErrorNotFound(err)
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }
if err := comment.LoadIssue(ctx); err != nil { if err := comment.LoadIssue(ctx); err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
@ -615,7 +615,7 @@ func editIssueComment(ctx *context.APIContext, form api.EditIssueCommentOption)
if errors.Is(err, user_model.ErrBlockedUser) { if errors.Is(err, user_model.ErrBlockedUser) {
ctx.APIError(http.StatusForbidden, err) ctx.APIError(http.StatusForbidden, err)
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }
@ -701,13 +701,13 @@ func deleteIssueComment(ctx *context.APIContext) {
if issues_model.IsErrCommentNotExist(err) { if issues_model.IsErrCommentNotExist(err) {
ctx.APIErrorNotFound(err) ctx.APIErrorNotFound(err)
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }
if err := comment.LoadIssue(ctx); err != nil { if err := comment.LoadIssue(ctx); err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
@ -725,7 +725,7 @@ func deleteIssueComment(ctx *context.APIContext) {
} }
if err = issue_service.DeleteComment(ctx, ctx.Doer, comment); err != nil { if err = issue_service.DeleteComment(ctx, ctx.Doer, comment); err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }

View File

@ -109,7 +109,7 @@ func ListIssueCommentAttachments(ctx *context.APIContext) {
} }
if err := comment.LoadAttachments(ctx); err != nil { if err := comment.LoadAttachments(ctx); err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
@ -179,7 +179,7 @@ func CreateIssueCommentAttachment(ctx *context.APIContext) {
// Get uploaded file from request // Get uploaded file from request
file, header, err := ctx.Req.FormFile("attachment") file, header, err := ctx.Req.FormFile("attachment")
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
defer file.Close() defer file.Close()
@ -200,13 +200,13 @@ func CreateIssueCommentAttachment(ctx *context.APIContext) {
if upload.IsErrFileTypeForbidden(err) { if upload.IsErrFileTypeForbidden(err) {
ctx.APIError(http.StatusUnprocessableEntity, err) ctx.APIError(http.StatusUnprocessableEntity, err)
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }
if err := comment.LoadAttachments(ctx); err != nil { if err := comment.LoadAttachments(ctx); err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
@ -282,7 +282,7 @@ func EditIssueCommentAttachment(ctx *context.APIContext) {
ctx.APIError(http.StatusUnprocessableEntity, err) ctx.APIError(http.StatusUnprocessableEntity, err)
return return
} }
ctx.APIError(http.StatusInternalServerError, attach) ctx.APIErrorInternal(err)
return return
} }
ctx.JSON(http.StatusCreated, convert.ToAPIAttachment(ctx.Repo.Repository, attach)) ctx.JSON(http.StatusCreated, convert.ToAPIAttachment(ctx.Repo.Repository, attach))
@ -331,7 +331,7 @@ func DeleteIssueCommentAttachment(ctx *context.APIContext) {
} }
if err := repo_model.DeleteAttachment(ctx, attach, true); err != nil { if err := repo_model.DeleteAttachment(ctx, attach, true); err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
ctx.Status(http.StatusNoContent) ctx.Status(http.StatusNoContent)
@ -340,11 +340,11 @@ func DeleteIssueCommentAttachment(ctx *context.APIContext) {
func getIssueCommentSafe(ctx *context.APIContext) *issues_model.Comment { func getIssueCommentSafe(ctx *context.APIContext) *issues_model.Comment {
comment, err := issues_model.GetCommentByID(ctx, ctx.PathParamInt64("id")) comment, err := issues_model.GetCommentByID(ctx, ctx.PathParamInt64("id"))
if err != nil { if err != nil {
ctx.NotFoundOrServerError("GetCommentByID", issues_model.IsErrCommentNotExist, err) ctx.NotFoundOrServerError(err)
return nil return nil
} }
if err := comment.LoadIssue(ctx); err != nil { if err := comment.LoadIssue(ctx); err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return nil return nil
} }
if comment.Issue == nil || comment.Issue.RepoID != ctx.Repo.Repository.ID { if comment.Issue == nil || comment.Issue.RepoID != ctx.Repo.Repository.ID {
@ -385,7 +385,7 @@ func canUserWriteIssueCommentAttachment(ctx *context.APIContext, comment *issues
func getIssueCommentAttachmentSafeRead(ctx *context.APIContext, comment *issues_model.Comment) *repo_model.Attachment { func getIssueCommentAttachmentSafeRead(ctx *context.APIContext, comment *issues_model.Comment) *repo_model.Attachment {
attachment, err := repo_model.GetAttachmentByID(ctx, ctx.PathParamInt64("attachment_id")) attachment, err := repo_model.GetAttachmentByID(ctx, ctx.PathParamInt64("attachment_id"))
if err != nil { if err != nil {
ctx.NotFoundOrServerError("GetAttachmentByID", repo_model.IsErrAttachmentNotExist, err) ctx.NotFoundOrServerError(err)
return nil return nil
} }
if !attachmentBelongsToRepoOrComment(ctx, attachment, comment) { if !attachmentBelongsToRepoOrComment(ctx, attachment, comment) {

View File

@ -66,7 +66,7 @@ func GetIssueDependencies(ctx *context.APIContext) {
if issues_model.IsErrIssueNotExist(err) { if issues_model.IsErrIssueNotExist(err) {
ctx.APIErrorNotFound("IsErrIssueNotExist", err) ctx.APIErrorNotFound("IsErrIssueNotExist", err)
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }
@ -98,7 +98,7 @@ func GetIssueDependencies(ctx *context.APIContext) {
PageSize: limit, PageSize: limit,
}) })
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
@ -342,7 +342,7 @@ func GetIssueBlocks(ctx *context.APIContext) {
deps, err := issue.BlockingDependencies(ctx) deps, err := issue.BlockingDependencies(ctx)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
@ -504,7 +504,7 @@ func getParamsIssue(ctx *context.APIContext) *issues_model.Issue {
if issues_model.IsErrIssueNotExist(err) { if issues_model.IsErrIssueNotExist(err) {
ctx.APIErrorNotFound("IsErrIssueNotExist", err) ctx.APIErrorNotFound("IsErrIssueNotExist", err)
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return nil return nil
} }
@ -525,7 +525,7 @@ func getFormIssue(ctx *context.APIContext, form *api.IssueMeta) *issues_model.Is
if repo_model.IsErrRepoNotExist(err) { if repo_model.IsErrRepoNotExist(err) {
ctx.APIErrorNotFound("IsErrRepoNotExist", err) ctx.APIErrorNotFound("IsErrRepoNotExist", err)
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return nil return nil
} }
@ -538,7 +538,7 @@ func getFormIssue(ctx *context.APIContext, form *api.IssueMeta) *issues_model.Is
if issues_model.IsErrIssueNotExist(err) { if issues_model.IsErrIssueNotExist(err) {
ctx.APIErrorNotFound("IsErrIssueNotExist", err) ctx.APIErrorNotFound("IsErrIssueNotExist", err)
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return nil return nil
} }
@ -553,7 +553,7 @@ func getPermissionForRepo(ctx *context.APIContext, repo *repo_model.Repository)
perm, err := access_model.GetUserRepoPermission(ctx, repo, ctx.Doer) perm, err := access_model.GetUserRepoPermission(ctx, repo, ctx.Doer)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return nil return nil
} }
@ -581,7 +581,7 @@ func createIssueDependency(ctx *context.APIContext, target, dependency *issues_m
err := issues_model.CreateIssueDependency(ctx, ctx.Doer, target, dependency) err := issues_model.CreateIssueDependency(ctx, ctx.Doer, target, dependency)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
} }
@ -607,7 +607,7 @@ func removeIssueDependency(ctx *context.APIContext, target, dependency *issues_m
err := issues_model.RemoveIssueDependency(ctx, ctx.Doer, target, dependency, issues_model.DependencyTypeBlockedBy) err := issues_model.RemoveIssueDependency(ctx, ctx.Doer, target, dependency, issues_model.DependencyTypeBlockedBy)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
} }

View File

@ -52,13 +52,13 @@ func ListIssueLabels(ctx *context.APIContext) {
if issues_model.IsErrIssueNotExist(err) { if issues_model.IsErrIssueNotExist(err) {
ctx.APIErrorNotFound() ctx.APIErrorNotFound()
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }
if err := issue.LoadAttributes(ctx); err != nil { if err := issue.LoadAttributes(ctx); err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
@ -110,13 +110,13 @@ func AddIssueLabels(ctx *context.APIContext) {
} }
if err = issue_service.AddLabels(ctx, issue, ctx.Doer, labels); err != nil { if err = issue_service.AddLabels(ctx, issue, ctx.Doer, labels); err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
labels, err = issues_model.GetLabelsByIssueID(ctx, issue.ID) labels, err = issues_model.GetLabelsByIssueID(ctx, issue.ID)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
@ -168,7 +168,7 @@ func DeleteIssueLabel(ctx *context.APIContext) {
if issues_model.IsErrIssueNotExist(err) { if issues_model.IsErrIssueNotExist(err) {
ctx.APIErrorNotFound() ctx.APIErrorNotFound()
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }
@ -183,13 +183,13 @@ func DeleteIssueLabel(ctx *context.APIContext) {
if issues_model.IsErrLabelNotExist(err) { if issues_model.IsErrLabelNotExist(err) {
ctx.APIError(http.StatusUnprocessableEntity, err) ctx.APIError(http.StatusUnprocessableEntity, err)
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }
if err := issue_service.RemoveLabel(ctx, issue, ctx.Doer, label); err != nil { if err := issue_service.RemoveLabel(ctx, issue, ctx.Doer, label); err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
@ -240,13 +240,13 @@ func ReplaceIssueLabels(ctx *context.APIContext) {
} }
if err := issue_service.ReplaceLabels(ctx, issue, ctx.Doer, labels); err != nil { if err := issue_service.ReplaceLabels(ctx, issue, ctx.Doer, labels); err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
labels, err = issues_model.GetLabelsByIssueID(ctx, issue.ID) labels, err = issues_model.GetLabelsByIssueID(ctx, issue.ID)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
@ -290,7 +290,7 @@ func ClearIssueLabels(ctx *context.APIContext) {
if issues_model.IsErrIssueNotExist(err) { if issues_model.IsErrIssueNotExist(err) {
ctx.APIErrorNotFound() ctx.APIErrorNotFound()
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }
@ -301,7 +301,7 @@ func ClearIssueLabels(ctx *context.APIContext) {
} }
if err := issue_service.ClearLabels(ctx, issue, ctx.Doer); err != nil { if err := issue_service.ClearLabels(ctx, issue, ctx.Doer); err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
@ -314,7 +314,7 @@ func prepareForReplaceOrAdd(ctx *context.APIContext, form api.IssueLabelsOption)
if issues_model.IsErrIssueNotExist(err) { if issues_model.IsErrIssueNotExist(err) {
ctx.APIErrorNotFound() ctx.APIErrorNotFound()
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return nil, nil, err return nil, nil, err
} }
@ -347,14 +347,14 @@ func prepareForReplaceOrAdd(ctx *context.APIContext, form api.IssueLabelsOption)
if len(labelNames) > 0 { if len(labelNames) > 0 {
repoLabelIDs, err := issues_model.GetLabelIDsInRepoByNames(ctx, ctx.Repo.Repository.ID, labelNames) repoLabelIDs, err := issues_model.GetLabelIDsInRepoByNames(ctx, ctx.Repo.Repository.ID, labelNames)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return nil, nil, err return nil, nil, err
} }
labelIDs = append(labelIDs, repoLabelIDs...) labelIDs = append(labelIDs, repoLabelIDs...)
if ctx.Repo.Owner.IsOrganization() { if ctx.Repo.Owner.IsOrganization() {
orgLabelIDs, err := issues_model.GetLabelIDsInOrgByNames(ctx, ctx.Repo.Owner.ID, labelNames) orgLabelIDs, err := issues_model.GetLabelIDsInOrgByNames(ctx, ctx.Repo.Owner.ID, labelNames)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return nil, nil, err return nil, nil, err
} }
labelIDs = append(labelIDs, orgLabelIDs...) labelIDs = append(labelIDs, orgLabelIDs...)
@ -363,7 +363,7 @@ func prepareForReplaceOrAdd(ctx *context.APIContext, form api.IssueLabelsOption)
labels, err := issues_model.GetLabelsByIDs(ctx, labelIDs, "id", "repo_id", "org_id", "name", "exclusive") labels, err := issues_model.GetLabelsByIDs(ctx, labelIDs, "id", "repo_id", "org_id", "name", "exclusive")
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return nil, nil, err return nil, nil, err
} }

View File

@ -48,7 +48,7 @@ func PinIssue(ctx *context.APIContext) {
} else if issues_model.IsErrIssueMaxPinReached(err) { } else if issues_model.IsErrIssueMaxPinReached(err) {
ctx.APIError(http.StatusBadRequest, err) ctx.APIError(http.StatusBadRequest, err)
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }
@ -56,13 +56,13 @@ func PinIssue(ctx *context.APIContext) {
// If we don't do this, it will crash when trying to add the pin event to the comment history // If we don't do this, it will crash when trying to add the pin event to the comment history
err = issue.LoadRepo(ctx) err = issue.LoadRepo(ctx)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
err = issues_model.PinIssue(ctx, issue, ctx.Doer) err = issues_model.PinIssue(ctx, issue, ctx.Doer)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
@ -103,7 +103,7 @@ func UnpinIssue(ctx *context.APIContext) {
if issues_model.IsErrIssueNotExist(err) { if issues_model.IsErrIssueNotExist(err) {
ctx.APIErrorNotFound() ctx.APIErrorNotFound()
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }
@ -111,13 +111,13 @@ func UnpinIssue(ctx *context.APIContext) {
// If we don't do this, it will crash when trying to add the unpin event to the comment history // If we don't do this, it will crash when trying to add the unpin event to the comment history
err = issue.LoadRepo(ctx) err = issue.LoadRepo(ctx)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
err = issues_model.UnpinIssue(ctx, issue, ctx.Doer) err = issues_model.UnpinIssue(ctx, issue, ctx.Doer)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
@ -164,14 +164,14 @@ func MoveIssuePin(ctx *context.APIContext) {
if issues_model.IsErrIssueNotExist(err) { if issues_model.IsErrIssueNotExist(err) {
ctx.APIErrorNotFound() ctx.APIErrorNotFound()
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }
err = issues_model.MovePin(ctx, issue, int(ctx.PathParamInt64("position"))) err = issues_model.MovePin(ctx, issue, int(ctx.PathParamInt64("position")))
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
@ -203,7 +203,7 @@ func ListPinnedIssues(ctx *context.APIContext) {
// "$ref": "#/responses/notFound" // "$ref": "#/responses/notFound"
issues, err := issues_model.GetPinnedIssues(ctx, ctx.Repo.Repository.ID, false) issues, err := issues_model.GetPinnedIssues(ctx, ctx.Repo.Repository.ID, false)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
@ -235,29 +235,29 @@ func ListPinnedPullRequests(ctx *context.APIContext) {
// "$ref": "#/responses/notFound" // "$ref": "#/responses/notFound"
issues, err := issues_model.GetPinnedIssues(ctx, ctx.Repo.Repository.ID, true) issues, err := issues_model.GetPinnedIssues(ctx, ctx.Repo.Repository.ID, true)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
apiPrs := make([]*api.PullRequest, len(issues)) apiPrs := make([]*api.PullRequest, len(issues))
if err := issues.LoadPullRequests(ctx); err != nil { if err := issues.LoadPullRequests(ctx); err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
for i, currentIssue := range issues { for i, currentIssue := range issues {
pr := currentIssue.PullRequest pr := currentIssue.PullRequest
if err = pr.LoadAttributes(ctx); err != nil { if err = pr.LoadAttributes(ctx); err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
if err = pr.LoadBaseRepo(ctx); err != nil { if err = pr.LoadBaseRepo(ctx); err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
if err = pr.LoadHeadRepo(ctx); err != nil { if err = pr.LoadHeadRepo(ctx); err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
@ -295,13 +295,13 @@ func AreNewIssuePinsAllowed(ctx *context.APIContext) {
pinsAllowed.Issues, err = issues_model.IsNewPinAllowed(ctx, ctx.Repo.Repository.ID, false) pinsAllowed.Issues, err = issues_model.IsNewPinAllowed(ctx, ctx.Repo.Repository.ID, false)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
pinsAllowed.PullRequests, err = issues_model.IsNewPinAllowed(ctx, ctx.Repo.Repository.ID, true) pinsAllowed.PullRequests, err = issues_model.IsNewPinAllowed(ctx, ctx.Repo.Repository.ID, true)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }

View File

@ -56,13 +56,13 @@ func GetIssueCommentReactions(ctx *context.APIContext) {
if issues_model.IsErrCommentNotExist(err) { if issues_model.IsErrCommentNotExist(err) {
ctx.APIErrorNotFound(err) ctx.APIErrorNotFound(err)
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }
if err := comment.LoadIssue(ctx); err != nil { if err := comment.LoadIssue(ctx); err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
@ -78,12 +78,12 @@ func GetIssueCommentReactions(ctx *context.APIContext) {
reactions, _, err := issues_model.FindCommentReactions(ctx, comment.IssueID, comment.ID) reactions, _, err := issues_model.FindCommentReactions(ctx, comment.IssueID, comment.ID)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
_, err = reactions.LoadUsers(ctx, ctx.Repo.Repository) _, err = reactions.LoadUsers(ctx, ctx.Repo.Repository)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
@ -193,13 +193,13 @@ func changeIssueCommentReaction(ctx *context.APIContext, form api.EditReactionOp
if issues_model.IsErrCommentNotExist(err) { if issues_model.IsErrCommentNotExist(err) {
ctx.APIErrorNotFound(err) ctx.APIErrorNotFound(err)
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }
if err = comment.LoadIssue(ctx); err != nil { if err = comment.LoadIssue(ctx); err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
@ -231,7 +231,7 @@ func changeIssueCommentReaction(ctx *context.APIContext, form api.EditReactionOp
Created: reaction.CreatedUnix.AsTime(), Created: reaction.CreatedUnix.AsTime(),
}) })
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }
@ -245,7 +245,7 @@ func changeIssueCommentReaction(ctx *context.APIContext, form api.EditReactionOp
// DeleteIssueCommentReaction part // DeleteIssueCommentReaction part
err = issues_model.DeleteCommentReaction(ctx, ctx.Doer.ID, comment.Issue.ID, comment.ID, form.Reaction) err = issues_model.DeleteCommentReaction(ctx, ctx.Doer.ID, comment.Issue.ID, comment.ID, form.Reaction)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
// ToDo respond 204 // ToDo respond 204
@ -300,7 +300,7 @@ func GetIssueReactions(ctx *context.APIContext) {
if issues_model.IsErrIssueNotExist(err) { if issues_model.IsErrIssueNotExist(err) {
ctx.APIErrorNotFound() ctx.APIErrorNotFound()
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }
@ -312,12 +312,12 @@ func GetIssueReactions(ctx *context.APIContext) {
reactions, count, err := issues_model.FindIssueReactions(ctx, issue.ID, utils.GetListOptions(ctx)) reactions, count, err := issues_model.FindIssueReactions(ctx, issue.ID, utils.GetListOptions(ctx))
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
_, err = reactions.LoadUsers(ctx, ctx.Repo.Repository) _, err = reactions.LoadUsers(ctx, ctx.Repo.Repository)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
@ -424,7 +424,7 @@ func changeIssueReaction(ctx *context.APIContext, form api.EditReactionOption, i
if issues_model.IsErrIssueNotExist(err) { if issues_model.IsErrIssueNotExist(err) {
ctx.APIErrorNotFound() ctx.APIErrorNotFound()
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }
@ -447,7 +447,7 @@ func changeIssueReaction(ctx *context.APIContext, form api.EditReactionOption, i
Created: reaction.CreatedUnix.AsTime(), Created: reaction.CreatedUnix.AsTime(),
}) })
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }
@ -461,7 +461,7 @@ func changeIssueReaction(ctx *context.APIContext, form api.EditReactionOption, i
// DeleteIssueReaction part // DeleteIssueReaction part
err = issues_model.DeleteIssueReaction(ctx, ctx.Doer.ID, issue.ID, form.Reaction) err = issues_model.DeleteIssueReaction(ctx, ctx.Doer.ID, issue.ID, form.Reaction)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
// ToDo respond 204 // ToDo respond 204

View File

@ -55,7 +55,7 @@ func StartIssueStopwatch(ctx *context.APIContext) {
} }
if err := issues_model.CreateIssueStopwatch(ctx, ctx.Doer, issue); err != nil { if err := issues_model.CreateIssueStopwatch(ctx, ctx.Doer, issue); err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
@ -104,7 +104,7 @@ func StopIssueStopwatch(ctx *context.APIContext) {
} }
if err := issues_model.FinishIssueStopwatch(ctx, ctx.Doer, issue); err != nil { if err := issues_model.FinishIssueStopwatch(ctx, ctx.Doer, issue); err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
@ -153,7 +153,7 @@ func DeleteIssueStopwatch(ctx *context.APIContext) {
} }
if err := issues_model.CancelStopwatch(ctx, ctx.Doer, issue); err != nil { if err := issues_model.CancelStopwatch(ctx, ctx.Doer, issue); err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
@ -166,7 +166,7 @@ func prepareIssueStopwatch(ctx *context.APIContext, shouldExist bool) (*issues_m
if issues_model.IsErrIssueNotExist(err) { if issues_model.IsErrIssueNotExist(err) {
ctx.APIErrorNotFound() ctx.APIErrorNotFound()
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return nil, err return nil, err
@ -220,7 +220,7 @@ func GetStopwatches(ctx *context.APIContext) {
sws, err := issues_model.GetUserStopwatches(ctx, ctx.Doer.ID, utils.GetListOptions(ctx)) sws, err := issues_model.GetUserStopwatches(ctx, ctx.Doer.ID, utils.GetListOptions(ctx))
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
@ -232,7 +232,7 @@ func GetStopwatches(ctx *context.APIContext) {
apiSWs, err := convert.ToStopWatches(ctx, sws) apiSWs, err := convert.ToStopWatches(ctx, sws)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }

View File

@ -109,7 +109,7 @@ func setIssueSubscription(ctx *context.APIContext, watch bool) {
if issues_model.IsErrIssueNotExist(err) { if issues_model.IsErrIssueNotExist(err) {
ctx.APIErrorNotFound() ctx.APIErrorNotFound()
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
@ -120,7 +120,7 @@ func setIssueSubscription(ctx *context.APIContext, watch bool) {
if user_model.IsErrUserNotExist(err) { if user_model.IsErrUserNotExist(err) {
ctx.APIErrorNotFound() ctx.APIErrorNotFound()
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
@ -134,7 +134,7 @@ func setIssueSubscription(ctx *context.APIContext, watch bool) {
current, err := issues_model.CheckIssueWatch(ctx, user, issue) current, err := issues_model.CheckIssueWatch(ctx, user, issue)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
@ -146,7 +146,7 @@ func setIssueSubscription(ctx *context.APIContext, watch bool) {
// Update watch state // Update watch state
if err := issues_model.CreateOrUpdateIssueWatch(ctx, user.ID, issue.ID, watch); err != nil { if err := issues_model.CreateOrUpdateIssueWatch(ctx, user.ID, issue.ID, watch); err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
@ -190,7 +190,7 @@ func CheckIssueSubscription(ctx *context.APIContext) {
if issues_model.IsErrIssueNotExist(err) { if issues_model.IsErrIssueNotExist(err) {
ctx.APIErrorNotFound() ctx.APIErrorNotFound()
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
@ -256,7 +256,7 @@ func GetIssueSubscribers(ctx *context.APIContext) {
if issues_model.IsErrIssueNotExist(err) { if issues_model.IsErrIssueNotExist(err) {
ctx.APIErrorNotFound() ctx.APIErrorNotFound()
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
@ -264,7 +264,7 @@ func GetIssueSubscribers(ctx *context.APIContext) {
iwl, err := issues_model.GetIssueWatchers(ctx, issue.ID, utils.GetListOptions(ctx)) iwl, err := issues_model.GetIssueWatchers(ctx, issue.ID, utils.GetListOptions(ctx))
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
@ -275,7 +275,7 @@ func GetIssueSubscribers(ctx *context.APIContext) {
users, err := user_model.GetUsersByIDs(ctx, userIDs) users, err := user_model.GetUsersByIDs(ctx, userIDs)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
apiUsers := make([]*api.User, 0, len(users)) apiUsers := make([]*api.User, 0, len(users))
@ -285,7 +285,7 @@ func GetIssueSubscribers(ctx *context.APIContext) {
count, err := issues_model.CountIssueWatchers(ctx, issue.ID) count, err := issues_model.CountIssueWatchers(ctx, issue.ID)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }

View File

@ -80,7 +80,7 @@ func ListTrackedTimes(ctx *context.APIContext) {
if issues_model.IsErrIssueNotExist(err) { if issues_model.IsErrIssueNotExist(err) {
ctx.APIErrorNotFound(err) ctx.APIErrorNotFound(err)
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }
@ -97,7 +97,7 @@ func ListTrackedTimes(ctx *context.APIContext) {
if user_model.IsErrUserNotExist(err) { if user_model.IsErrUserNotExist(err) {
ctx.APIError(http.StatusNotFound, err) ctx.APIError(http.StatusNotFound, err)
} else if err != nil { } else if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
opts.UserID = user.ID opts.UserID = user.ID
@ -129,11 +129,11 @@ func ListTrackedTimes(ctx *context.APIContext) {
trackedTimes, err := issues_model.GetTrackedTimes(ctx, opts) trackedTimes, err := issues_model.GetTrackedTimes(ctx, opts)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
if err = trackedTimes.LoadAttributes(ctx); err != nil { if err = trackedTimes.LoadAttributes(ctx); err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
@ -186,7 +186,7 @@ func AddTime(ctx *context.APIContext) {
if issues_model.IsErrIssueNotExist(err) { if issues_model.IsErrIssueNotExist(err) {
ctx.APIErrorNotFound(err) ctx.APIErrorNotFound(err)
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }
@ -206,7 +206,7 @@ func AddTime(ctx *context.APIContext) {
// allow only RepoAdmin, Admin and User to add time // allow only RepoAdmin, Admin and User to add time
user, err = user_model.GetUserByName(ctx, form.User) user, err = user_model.GetUserByName(ctx, form.User)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
} }
} }
@ -218,11 +218,11 @@ func AddTime(ctx *context.APIContext) {
trackedTime, err := issues_model.AddTime(ctx, user, issue, form.Time, created) trackedTime, err := issues_model.AddTime(ctx, user, issue, form.Time, created)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
if err = trackedTime.LoadAttributes(ctx); err != nil { if err = trackedTime.LoadAttributes(ctx); err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
ctx.JSON(http.StatusOK, convert.ToTrackedTime(ctx, user, trackedTime)) ctx.JSON(http.StatusOK, convert.ToTrackedTime(ctx, user, trackedTime))
@ -269,7 +269,7 @@ func ResetIssueTime(ctx *context.APIContext) {
if issues_model.IsErrIssueNotExist(err) { if issues_model.IsErrIssueNotExist(err) {
ctx.APIErrorNotFound(err) ctx.APIErrorNotFound(err)
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }
@ -288,7 +288,7 @@ func ResetIssueTime(ctx *context.APIContext) {
if db.IsErrNotExist(err) { if db.IsErrNotExist(err) {
ctx.APIError(http.StatusNotFound, err) ctx.APIError(http.StatusNotFound, err)
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }
@ -342,7 +342,7 @@ func DeleteTime(ctx *context.APIContext) {
if issues_model.IsErrIssueNotExist(err) { if issues_model.IsErrIssueNotExist(err) {
ctx.APIErrorNotFound(err) ctx.APIErrorNotFound(err)
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }
@ -362,7 +362,7 @@ func DeleteTime(ctx *context.APIContext) {
ctx.APIErrorNotFound(err) ctx.APIErrorNotFound(err)
return return
} }
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
if time.Deleted { if time.Deleted {
@ -378,7 +378,7 @@ func DeleteTime(ctx *context.APIContext) {
err = issues_model.DeleteTime(ctx, time) err = issues_model.DeleteTime(ctx, time)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
ctx.Status(http.StatusNoContent) ctx.Status(http.StatusNoContent)
@ -427,7 +427,7 @@ func ListTrackedTimesByUser(ctx *context.APIContext) {
if user_model.IsErrUserNotExist(err) { if user_model.IsErrUserNotExist(err) {
ctx.APIErrorNotFound(err) ctx.APIErrorNotFound(err)
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }
@ -448,11 +448,11 @@ func ListTrackedTimesByUser(ctx *context.APIContext) {
trackedTimes, err := issues_model.GetTrackedTimes(ctx, opts) trackedTimes, err := issues_model.GetTrackedTimes(ctx, opts)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
if err = trackedTimes.LoadAttributes(ctx); err != nil { if err = trackedTimes.LoadAttributes(ctx); err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
ctx.JSON(http.StatusOK, convert.ToTrackedTimeList(ctx, ctx.Doer, trackedTimes)) ctx.JSON(http.StatusOK, convert.ToTrackedTimeList(ctx, ctx.Doer, trackedTimes))
@ -525,7 +525,7 @@ func ListTrackedTimesByRepository(ctx *context.APIContext) {
if user_model.IsErrUserNotExist(err) { if user_model.IsErrUserNotExist(err) {
ctx.APIError(http.StatusNotFound, err) ctx.APIError(http.StatusNotFound, err)
} else if err != nil { } else if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
opts.UserID = user.ID opts.UserID = user.ID
@ -558,11 +558,11 @@ func ListTrackedTimesByRepository(ctx *context.APIContext) {
trackedTimes, err := issues_model.GetTrackedTimes(ctx, opts) trackedTimes, err := issues_model.GetTrackedTimes(ctx, opts)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
if err = trackedTimes.LoadAttributes(ctx); err != nil { if err = trackedTimes.LoadAttributes(ctx); err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
@ -619,12 +619,12 @@ func ListMyTrackedTimes(ctx *context.APIContext) {
trackedTimes, err := issues_model.GetTrackedTimes(ctx, opts) trackedTimes, err := issues_model.GetTrackedTimes(ctx, opts)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
if err = trackedTimes.LoadAttributes(ctx); err != nil { if err = trackedTimes.LoadAttributes(ctx); err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }

View File

@ -100,7 +100,7 @@ func ListDeployKeys(ctx *context.APIContext) {
apiKeys := make([]*api.DeployKey, len(keys)) apiKeys := make([]*api.DeployKey, len(keys))
for i := range keys { for i := range keys {
if err := keys[i].GetContent(ctx); err != nil { if err := keys[i].GetContent(ctx); err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
apiKeys[i] = convert.ToDeployKey(apiLink, keys[i]) apiKeys[i] = convert.ToDeployKey(apiLink, keys[i])
@ -148,7 +148,7 @@ func GetDeployKey(ctx *context.APIContext) {
if asymkey_model.IsErrDeployKeyNotExist(err) { if asymkey_model.IsErrDeployKeyNotExist(err) {
ctx.APIErrorNotFound() ctx.APIErrorNotFound()
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }
@ -160,7 +160,7 @@ func GetDeployKey(ctx *context.APIContext) {
} }
if err = key.GetContent(ctx); err != nil { if err = key.GetContent(ctx); err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
@ -195,7 +195,7 @@ func HandleAddKeyError(ctx *context.APIContext, err error) {
case asymkey_model.IsErrDeployKeyNameAlreadyUsed(err): case asymkey_model.IsErrDeployKeyNameAlreadyUsed(err):
ctx.APIError(http.StatusUnprocessableEntity, "A key with the same name already exists") ctx.APIError(http.StatusUnprocessableEntity, "A key with the same name already exists")
default: default:
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
} }
@ -283,7 +283,7 @@ func DeleteDeploykey(ctx *context.APIContext) {
if asymkey_model.IsErrKeyAccessDenied(err) { if asymkey_model.IsErrKeyAccessDenied(err) {
ctx.APIError(http.StatusForbidden, "You do not have access to this key") ctx.APIError(http.StatusForbidden, "You do not have access to this key")
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }

View File

@ -51,7 +51,7 @@ func ListLabels(ctx *context.APIContext) {
labels, err := issues_model.GetLabelsByRepoID(ctx, ctx.Repo.Repository.ID, ctx.FormString("sort"), utils.GetListOptions(ctx)) labels, err := issues_model.GetLabelsByRepoID(ctx, ctx.Repo.Repository.ID, ctx.FormString("sort"), utils.GetListOptions(ctx))
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
@ -109,7 +109,7 @@ func GetLabel(ctx *context.APIContext) {
if issues_model.IsErrRepoLabelNotExist(err) { if issues_model.IsErrRepoLabelNotExist(err) {
ctx.APIErrorNotFound() ctx.APIErrorNotFound()
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }
@ -166,7 +166,7 @@ func CreateLabel(ctx *context.APIContext) {
} }
l.SetArchived(form.IsArchived) l.SetArchived(form.IsArchived)
if err := issues_model.NewLabel(ctx, l); err != nil { if err := issues_model.NewLabel(ctx, l); err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
@ -217,7 +217,7 @@ func EditLabel(ctx *context.APIContext) {
if issues_model.IsErrRepoLabelNotExist(err) { if issues_model.IsErrRepoLabelNotExist(err) {
ctx.APIErrorNotFound() ctx.APIErrorNotFound()
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }
@ -241,7 +241,7 @@ func EditLabel(ctx *context.APIContext) {
} }
l.SetArchived(form.IsArchived != nil && *form.IsArchived) l.SetArchived(form.IsArchived != nil && *form.IsArchived)
if err := issues_model.UpdateLabel(ctx, l); err != nil { if err := issues_model.UpdateLabel(ctx, l); err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
@ -277,7 +277,7 @@ func DeleteLabel(ctx *context.APIContext) {
// "$ref": "#/responses/notFound" // "$ref": "#/responses/notFound"
if err := issues_model.DeleteLabel(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("id")); err != nil { if err := issues_model.DeleteLabel(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("id")); err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }

View File

@ -74,7 +74,7 @@ func Migrate(ctx *context.APIContext) {
if user_model.IsErrUserNotExist(err) { if user_model.IsErrUserNotExist(err) {
ctx.APIError(http.StatusUnprocessableEntity, err) ctx.APIError(http.StatusUnprocessableEntity, err)
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }
@ -94,7 +94,7 @@ func Migrate(ctx *context.APIContext) {
// Check ownership of organization. // Check ownership of organization.
isOwner, err := organization.OrgFromUser(repoOwner).IsOwnedBy(ctx, ctx.Doer.ID) isOwner, err := organization.OrgFromUser(repoOwner).IsOwnedBy(ctx, ctx.Doer.ID)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} else if !isOwner { } else if !isOwner {
ctx.APIError(http.StatusForbidden, "Given user is not owner of organization.") ctx.APIError(http.StatusForbidden, "Given user is not owner of organization.")
@ -129,7 +129,7 @@ func Migrate(ctx *context.APIContext) {
if form.LFS && len(form.LFSEndpoint) > 0 { if form.LFS && len(form.LFSEndpoint) > 0 {
ep := lfs.DetermineEndpoint("", form.LFSEndpoint) ep := lfs.DetermineEndpoint("", form.LFSEndpoint)
if ep == nil { if ep == nil {
ctx.APIError(http.StatusInternalServerError, ctx.Tr("repo.migrate.invalid_lfs_endpoint")) ctx.APIErrorInternal(errors.New("the LFS endpoint is not valid"))
return return
} }
err = migrations.IsMigrateURLAllowed(ep.String(), ctx.Doer) err = migrations.IsMigrateURLAllowed(ep.String(), ctx.Doer)
@ -249,7 +249,7 @@ func handleMigrateError(ctx *context.APIContext, repoOwner *user_model.User, err
} else if strings.Contains(err.Error(), "fatal:") { } else if strings.Contains(err.Error(), "fatal:") {
ctx.APIError(http.StatusUnprocessableEntity, fmt.Sprintf("Migration failed: %v.", err)) ctx.APIError(http.StatusUnprocessableEntity, fmt.Sprintf("Migration failed: %v.", err))
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
} }
} }
@ -269,9 +269,9 @@ func handleRemoteAddrError(ctx *context.APIContext, err error) {
case addrErr.IsInvalidPath: case addrErr.IsInvalidPath:
ctx.APIError(http.StatusUnprocessableEntity, "Invalid local path, it does not exist or not a directory.") ctx.APIError(http.StatusUnprocessableEntity, "Invalid local path, it does not exist or not a directory.")
default: default:
ctx.APIError(http.StatusInternalServerError, "Unknown error type (ErrInvalidCloneAddr): "+err.Error()) ctx.APIErrorInternal(fmt.Errorf("unknown error type (ErrInvalidCloneAddr): %w", err))
} }
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
} }

View File

@ -74,7 +74,7 @@ func ListMilestones(ctx *context.APIContext) {
Name: ctx.FormString("name"), Name: ctx.FormString("name"),
}) })
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
@ -173,7 +173,7 @@ func CreateMilestone(ctx *context.APIContext) {
} }
if err := issues_model.NewMilestone(ctx, milestone); err != nil { if err := issues_model.NewMilestone(ctx, milestone); err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
ctx.JSON(http.StatusCreated, convert.ToAPIMilestone(milestone)) ctx.JSON(http.StatusCreated, convert.ToAPIMilestone(milestone))
@ -233,7 +233,7 @@ func EditMilestone(ctx *context.APIContext) {
} }
if err := issues_model.UpdateMilestone(ctx, milestone, oldIsClosed); err != nil { if err := issues_model.UpdateMilestone(ctx, milestone, oldIsClosed); err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
ctx.JSON(http.StatusOK, convert.ToAPIMilestone(milestone)) ctx.JSON(http.StatusOK, convert.ToAPIMilestone(milestone))
@ -272,7 +272,7 @@ func DeleteMilestone(ctx *context.APIContext) {
} }
if err := issues_model.DeleteMilestoneByRepoID(ctx, ctx.Repo.Repository.ID, m.ID); err != nil { if err := issues_model.DeleteMilestoneByRepoID(ctx, ctx.Repo.Repository.ID, m.ID); err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
ctx.Status(http.StatusNoContent) ctx.Status(http.StatusNoContent)
@ -288,7 +288,7 @@ func getMilestoneByIDOrName(ctx *context.APIContext) *issues_model.Milestone {
if err == nil { if err == nil {
return milestone return milestone
} else if !issues_model.IsErrMilestoneNotExist(err) { } else if !issues_model.IsErrMilestoneNotExist(err) {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return nil return nil
} }
} }
@ -299,7 +299,7 @@ func getMilestoneByIDOrName(ctx *context.APIContext) *issues_model.Milestone {
ctx.APIErrorNotFound() ctx.APIErrorNotFound()
return nil return nil
} }
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return nil return nil
} }

View File

@ -66,7 +66,7 @@ func MirrorSync(ctx *context.APIContext) {
ctx.APIError(http.StatusBadRequest, "Repository is not a mirror") ctx.APIError(http.StatusBadRequest, "Repository is not a mirror")
return return
} }
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
@ -116,7 +116,7 @@ func PushMirrorSync(ctx *context.APIContext) {
for _, mirror := range pushMirrors { for _, mirror := range pushMirrors {
ok := mirror_service.SyncPushMirror(ctx, mirror.ID) ok := mirror_service.SyncPushMirror(ctx, mirror.ID)
if !ok { if !ok {
ctx.APIError(http.StatusInternalServerError, "error occurred when syncing push mirror "+mirror.RemoteName) ctx.APIErrorInternal(errors.New("error occurred when syncing push mirror " + mirror.RemoteName))
return return
} }
} }
@ -230,7 +230,7 @@ func GetPushMirrorByName(ctx *context.APIContext) {
RemoteName: mirrorName, RemoteName: mirrorName,
}.ToConds()) }.ToConds())
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} else if !exist { } else if !exist {
ctx.APIError(http.StatusNotFound, nil) ctx.APIError(http.StatusNotFound, nil)

View File

@ -71,7 +71,7 @@ func getNote(ctx *context.APIContext, identifier string) {
if git.IsErrNotExist(err) { if git.IsErrNotExist(err) {
ctx.APIErrorNotFound(err) ctx.APIErrorNotFound(err)
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }
@ -82,7 +82,7 @@ func getNote(ctx *context.APIContext, identifier string) {
ctx.APIErrorNotFound(identifier) ctx.APIErrorNotFound(identifier)
return return
} }
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
@ -96,7 +96,7 @@ func getNote(ctx *context.APIContext, identifier string) {
Files: files, Files: files,
}) })
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
apiNote := api.Note{Message: string(note.Message), Commit: cmt} apiNote := api.Note{Message: string(note.Message), Commit: cmt}

View File

@ -83,7 +83,7 @@ func ApplyDiffPatch(ctx *context.APIContext) {
} }
if !canWriteFiles(ctx, apiOpts.BranchName) { if !canWriteFiles(ctx, apiOpts.BranchName) {
ctx.APIError(http.StatusInternalServerError, repo_model.ErrUserDoesNotHaveAccessToRepo{ ctx.APIErrorInternal(repo_model.ErrUserDoesNotHaveAccessToRepo{
UserID: ctx.Doer.ID, UserID: ctx.Doer.ID,
RepoName: ctx.Repo.Repository.LowerName, RepoName: ctx.Repo.Repository.LowerName,
}) })
@ -105,7 +105,7 @@ func ApplyDiffPatch(ctx *context.APIContext) {
ctx.APIError(http.StatusNotFound, err) ctx.APIError(http.StatusNotFound, err)
return return
} }
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} else { } else {
ctx.JSON(http.StatusCreated, fileResponse) ctx.JSON(http.StatusCreated, fileResponse)
} }

View File

@ -108,7 +108,7 @@ func ListPullRequests(ctx *context.APIContext) {
labelIDs, err := base.StringsToInt64s(ctx.FormStrings("labels")) labelIDs, err := base.StringsToInt64s(ctx.FormStrings("labels"))
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
var posterID int64 var posterID int64
@ -118,7 +118,7 @@ func ListPullRequests(ctx *context.APIContext) {
if user_model.IsErrUserNotExist(err) { if user_model.IsErrUserNotExist(err) {
ctx.APIError(http.StatusBadRequest, err) ctx.APIError(http.StatusBadRequest, err)
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }
@ -134,13 +134,13 @@ func ListPullRequests(ctx *context.APIContext) {
PosterID: posterID, PosterID: posterID,
}) })
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
apiPrs, err := convert.ToAPIPullRequests(ctx, ctx.Repo.Repository, prs, ctx.Doer) apiPrs, err := convert.ToAPIPullRequests(ctx, ctx.Repo.Repository, prs, ctx.Doer)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
@ -184,17 +184,17 @@ func GetPullRequest(ctx *context.APIContext) {
if issues_model.IsErrPullRequestNotExist(err) { if issues_model.IsErrPullRequestNotExist(err) {
ctx.APIErrorNotFound() ctx.APIErrorNotFound()
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }
if err = pr.LoadBaseRepo(ctx); err != nil { if err = pr.LoadBaseRepo(ctx); err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
if err = pr.LoadHeadRepo(ctx); err != nil { if err = pr.LoadHeadRepo(ctx); err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
ctx.JSON(http.StatusOK, convert.ToAPIPullRequest(ctx, pr, ctx.Doer)) ctx.JSON(http.StatusOK, convert.ToAPIPullRequest(ctx, pr, ctx.Doer))
@ -254,7 +254,7 @@ func GetPullRequestByBaseHead(ctx *context.APIContext) {
if repo_model.IsErrRepoNotExist(err) { if repo_model.IsErrRepoNotExist(err) {
ctx.APIErrorNotFound() ctx.APIErrorNotFound()
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }
@ -269,17 +269,17 @@ func GetPullRequestByBaseHead(ctx *context.APIContext) {
if issues_model.IsErrPullRequestNotExist(err) { if issues_model.IsErrPullRequestNotExist(err) {
ctx.APIErrorNotFound() ctx.APIErrorNotFound()
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }
if err = pr.LoadBaseRepo(ctx); err != nil { if err = pr.LoadBaseRepo(ctx); err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
if err = pr.LoadHeadRepo(ctx); err != nil { if err = pr.LoadHeadRepo(ctx); err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
ctx.JSON(http.StatusOK, convert.ToAPIPullRequest(ctx, pr, ctx.Doer)) ctx.JSON(http.StatusOK, convert.ToAPIPullRequest(ctx, pr, ctx.Doer))
@ -417,7 +417,7 @@ func CreatePullRequest(ctx *context.APIContext) {
) )
if err != nil { if err != nil {
if !issues_model.IsErrPullRequestNotExist(err) { if !issues_model.IsErrPullRequestNotExist(err) {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
} else { } else {
@ -436,7 +436,7 @@ func CreatePullRequest(ctx *context.APIContext) {
if len(form.Labels) > 0 { if len(form.Labels) > 0 {
labels, err := issues_model.GetLabelsInRepoByIDs(ctx, ctx.Repo.Repository.ID, form.Labels) labels, err := issues_model.GetLabelsInRepoByIDs(ctx, ctx.Repo.Repository.ID, form.Labels)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
@ -448,7 +448,7 @@ func CreatePullRequest(ctx *context.APIContext) {
if ctx.Repo.Owner.IsOrganization() { if ctx.Repo.Owner.IsOrganization() {
orgLabels, err := issues_model.GetLabelsInOrgByIDs(ctx, ctx.Repo.Owner.ID, form.Labels) orgLabels, err := issues_model.GetLabelsInOrgByIDs(ctx, ctx.Repo.Owner.ID, form.Labels)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
@ -466,7 +466,7 @@ func CreatePullRequest(ctx *context.APIContext) {
if issues_model.IsErrMilestoneNotExist(err) { if issues_model.IsErrMilestoneNotExist(err) {
ctx.APIErrorNotFound() ctx.APIErrorNotFound()
} else { } else {
ctx.APIError(http.StatusInternalServerError, fmt.Errorf("GetMilestoneByRepoID: %w", err)) ctx.APIErrorInternal(fmt.Errorf("GetMilestoneByRepoID: %w", err))
} }
return return
} }
@ -506,7 +506,7 @@ func CreatePullRequest(ctx *context.APIContext) {
if user_model.IsErrUserNotExist(err) { if user_model.IsErrUserNotExist(err) {
ctx.APIError(http.StatusUnprocessableEntity, fmt.Sprintf("Assignee does not exist: [name: %s]", err)) ctx.APIError(http.StatusUnprocessableEntity, fmt.Sprintf("Assignee does not exist: [name: %s]", err))
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }
@ -514,13 +514,13 @@ func CreatePullRequest(ctx *context.APIContext) {
for _, aID := range assigneeIDs { for _, aID := range assigneeIDs {
assignee, err := user_model.GetUserByID(ctx, aID) assignee, err := user_model.GetUserByID(ctx, aID)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
valid, err := access_model.CanBeAssigned(ctx, assignee, repo, true) valid, err := access_model.CanBeAssigned(ctx, assignee, repo, true)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
if !valid { if !valid {
@ -549,7 +549,7 @@ func CreatePullRequest(ctx *context.APIContext) {
} else if errors.Is(err, issues_model.ErrMustCollaborator) { } else if errors.Is(err, issues_model.ErrMustCollaborator) {
ctx.APIError(http.StatusForbidden, err) ctx.APIError(http.StatusForbidden, err)
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }
@ -608,21 +608,21 @@ func EditPullRequest(ctx *context.APIContext) {
if issues_model.IsErrPullRequestNotExist(err) { if issues_model.IsErrPullRequestNotExist(err) {
ctx.APIErrorNotFound() ctx.APIErrorNotFound()
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }
err = pr.LoadIssue(ctx) err = pr.LoadIssue(ctx)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
issue := pr.Issue issue := pr.Issue
issue.Repo = ctx.Repo.Repository issue.Repo = ctx.Repo.Repository
if err := issue.LoadAttributes(ctx); err != nil { if err := issue.LoadAttributes(ctx); err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
@ -634,7 +634,7 @@ func EditPullRequest(ctx *context.APIContext) {
if len(form.Title) > 0 { if len(form.Title) > 0 {
err = issue_service.ChangeTitle(ctx, issue, ctx.Doer, form.Title) err = issue_service.ChangeTitle(ctx, issue, ctx.Doer, form.Title)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
} }
@ -646,7 +646,7 @@ func EditPullRequest(ctx *context.APIContext) {
return return
} }
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
} }
@ -661,7 +661,7 @@ func EditPullRequest(ctx *context.APIContext) {
} }
if err := issues_model.UpdateIssueDeadline(ctx, issue, deadlineUnix, ctx.Doer); err != nil { if err := issues_model.UpdateIssueDeadline(ctx, issue, deadlineUnix, ctx.Doer); err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
issue.DeadlineUnix = deadlineUnix issue.DeadlineUnix = deadlineUnix
@ -683,7 +683,7 @@ func EditPullRequest(ctx *context.APIContext) {
} else if errors.Is(err, user_model.ErrBlockedUser) { } else if errors.Is(err, user_model.ErrBlockedUser) {
ctx.APIError(http.StatusForbidden, err) ctx.APIError(http.StatusForbidden, err)
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }
@ -694,7 +694,7 @@ func EditPullRequest(ctx *context.APIContext) {
oldMilestoneID := issue.MilestoneID oldMilestoneID := issue.MilestoneID
issue.MilestoneID = form.Milestone issue.MilestoneID = form.Milestone
if err = issue_service.ChangeMilestoneAssign(ctx, issue, ctx.Doer, oldMilestoneID); err != nil { if err = issue_service.ChangeMilestoneAssign(ctx, issue, ctx.Doer, oldMilestoneID); err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
} }
@ -702,14 +702,14 @@ func EditPullRequest(ctx *context.APIContext) {
if ctx.Repo.CanWrite(unit.TypePullRequests) && form.Labels != nil { if ctx.Repo.CanWrite(unit.TypePullRequests) && form.Labels != nil {
labels, err := issues_model.GetLabelsInRepoByIDs(ctx, ctx.Repo.Repository.ID, form.Labels) labels, err := issues_model.GetLabelsInRepoByIDs(ctx, ctx.Repo.Repository.ID, form.Labels)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
if ctx.Repo.Owner.IsOrganization() { if ctx.Repo.Owner.IsOrganization() {
orgLabels, err := issues_model.GetLabelsInOrgByIDs(ctx, ctx.Repo.Owner.ID, form.Labels) orgLabels, err := issues_model.GetLabelsInOrgByIDs(ctx, ctx.Repo.Owner.ID, form.Labels)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
@ -717,7 +717,7 @@ func EditPullRequest(ctx *context.APIContext) {
} }
if err = issues_model.ReplaceIssueLabels(ctx, issue, labels, ctx.Doer); err != nil { if err = issues_model.ReplaceIssueLabels(ctx, issue, labels, ctx.Doer); err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
} }
@ -776,7 +776,7 @@ func EditPullRequest(ctx *context.APIContext) {
if issues_model.IsErrPullRequestNotExist(err) { if issues_model.IsErrPullRequestNotExist(err) {
ctx.APIErrorNotFound() ctx.APIErrorNotFound()
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }
@ -820,7 +820,7 @@ func IsPullRequestMerged(ctx *context.APIContext) {
if issues_model.IsErrPullRequestNotExist(err) { if issues_model.IsErrPullRequestNotExist(err) {
ctx.APIErrorNotFound() ctx.APIErrorNotFound()
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }
@ -878,18 +878,18 @@ func MergePullRequest(ctx *context.APIContext) {
if issues_model.IsErrPullRequestNotExist(err) { if issues_model.IsErrPullRequestNotExist(err) {
ctx.APIErrorNotFound("GetPullRequestByIndex", err) ctx.APIErrorNotFound("GetPullRequestByIndex", err)
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }
if err := pr.LoadHeadRepo(ctx); err != nil { if err := pr.LoadHeadRepo(ctx); err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
if err := pr.LoadIssue(ctx); err != nil { if err := pr.LoadIssue(ctx); err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
pr.Issue.Repo = ctx.Repo.Repository pr.Issue.Repo = ctx.Repo.Repository
@ -897,7 +897,7 @@ func MergePullRequest(ctx *context.APIContext) {
if ctx.IsSigned { if ctx.IsSigned {
// Update issue-user. // Update issue-user.
if err = activities_model.SetIssueReadBy(ctx, pr.Issue.ID, ctx.Doer.ID); err != nil { if err = activities_model.SetIssueReadBy(ctx, pr.Issue.ID, ctx.Doer.ID); err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
} }
@ -945,7 +945,7 @@ func MergePullRequest(ctx *context.APIContext) {
ctx.JSON(http.StatusConflict, err) ctx.JSON(http.StatusConflict, err)
return return
} }
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
ctx.Status(http.StatusOK) ctx.Status(http.StatusOK)
@ -960,7 +960,7 @@ func MergePullRequest(ctx *context.APIContext) {
if len(message) == 0 { if len(message) == 0 {
message, _, err = pull_service.GetDefaultMergeMessage(ctx, ctx.Repo.GitRepo, pr, repo_model.MergeStyle(form.Do)) message, _, err = pull_service.GetDefaultMergeMessage(ctx, ctx.Repo.GitRepo, pr, repo_model.MergeStyle(form.Do))
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
} }
@ -977,7 +977,7 @@ func MergePullRequest(ctx *context.APIContext) {
ctx.APIError(http.StatusConflict, err) ctx.APIError(http.StatusConflict, err)
return return
} }
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} else if scheduled { } else if scheduled {
// nothing more to do ... // nothing more to do ...
@ -1010,7 +1010,7 @@ func MergePullRequest(ctx *context.APIContext) {
ctx.APIError(http.StatusConflict, "PushRejected with remote message: "+errPushRej.Message) ctx.APIError(http.StatusConflict, "PushRejected with remote message: "+errPushRej.Message)
} }
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }
@ -1053,7 +1053,7 @@ func MergePullRequest(ctx *context.APIContext) {
case errors.Is(err, git_model.ErrBranchIsProtected): case errors.Is(err, git_model.ErrBranchIsProtected):
ctx.APIError(http.StatusForbidden, fmt.Errorf("branch protected")) ctx.APIError(http.StatusForbidden, fmt.Errorf("branch protected"))
default: default:
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }
@ -1094,7 +1094,7 @@ func parseCompareInfo(ctx *context.APIContext, form api.CreatePullRequestOption)
if user_model.IsErrUserNotExist(err) { if user_model.IsErrUserNotExist(err) {
ctx.APIErrorNotFound("GetUserByName") ctx.APIErrorNotFound("GetUserByName")
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return nil, nil return nil, nil
} }
@ -1110,7 +1110,7 @@ func parseCompareInfo(ctx *context.APIContext, form api.CreatePullRequestOption)
if headRepo == nil && !isSameRepo { if headRepo == nil && !isSameRepo {
err = baseRepo.GetBaseRepo(ctx) err = baseRepo.GetBaseRepo(ctx)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return nil, nil return nil, nil
} }
@ -1132,7 +1132,7 @@ func parseCompareInfo(ctx *context.APIContext, form api.CreatePullRequestOption)
} else { } else {
headGitRepo, err = gitrepo.OpenRepository(ctx, headRepo) headGitRepo, err = gitrepo.OpenRepository(ctx, headRepo)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return nil, nil return nil, nil
} }
closer = func() { _ = headGitRepo.Close() } closer = func() { _ = headGitRepo.Close() }
@ -1146,7 +1146,7 @@ func parseCompareInfo(ctx *context.APIContext, form api.CreatePullRequestOption)
// user should have permission to read baseRepo's codes and pulls, NOT headRepo's // user should have permission to read baseRepo's codes and pulls, NOT headRepo's
permBase, err := access_model.GetUserRepoPermission(ctx, baseRepo, ctx.Doer) permBase, err := access_model.GetUserRepoPermission(ctx, baseRepo, ctx.Doer)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return nil, nil return nil, nil
} }
@ -1160,7 +1160,7 @@ func parseCompareInfo(ctx *context.APIContext, form api.CreatePullRequestOption)
// TODO: could the logic be simplified if the headRepo is the same as the baseRepo? Need to think more about it. // TODO: could the logic be simplified if the headRepo is the same as the baseRepo? Need to think more about it.
permHead, err := access_model.GetUserRepoPermission(ctx, headRepo, ctx.Doer) permHead, err := access_model.GetUserRepoPermission(ctx, headRepo, ctx.Doer)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return nil, nil return nil, nil
} }
if !permHead.CanRead(unit.TypeCode) { if !permHead.CanRead(unit.TypeCode) {
@ -1184,7 +1184,7 @@ func parseCompareInfo(ctx *context.APIContext, form api.CreatePullRequestOption)
compareInfo, err := headGitRepo.GetCompareInfo(repo_model.RepoPath(baseRepo.Owner.Name, baseRepo.Name), baseRef.ShortName(), headRef.ShortName(), false, false) compareInfo, err := headGitRepo.GetCompareInfo(repo_model.RepoPath(baseRepo.Owner.Name, baseRepo.Name), baseRef.ShortName(), headRef.ShortName(), false, false)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return nil, nil return nil, nil
} }
@ -1238,7 +1238,7 @@ func UpdatePullRequest(ctx *context.APIContext) {
if issues_model.IsErrPullRequestNotExist(err) { if issues_model.IsErrPullRequestNotExist(err) {
ctx.APIErrorNotFound() ctx.APIErrorNotFound()
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }
@ -1249,7 +1249,7 @@ func UpdatePullRequest(ctx *context.APIContext) {
} }
if err = pr.LoadIssue(ctx); err != nil { if err = pr.LoadIssue(ctx); err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
@ -1259,11 +1259,11 @@ func UpdatePullRequest(ctx *context.APIContext) {
} }
if err = pr.LoadBaseRepo(ctx); err != nil { if err = pr.LoadBaseRepo(ctx); err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
if err = pr.LoadHeadRepo(ctx); err != nil { if err = pr.LoadHeadRepo(ctx); err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
@ -1271,7 +1271,7 @@ func UpdatePullRequest(ctx *context.APIContext) {
allowedUpdateByMerge, allowedUpdateByRebase, err := pull_service.IsUserAllowedToUpdate(ctx, pr, ctx.Doer) allowedUpdateByMerge, allowedUpdateByRebase, err := pull_service.IsUserAllowedToUpdate(ctx, pr, ctx.Doer)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
@ -1291,7 +1291,7 @@ func UpdatePullRequest(ctx *context.APIContext) {
ctx.APIError(http.StatusConflict, "rebase failed because of conflict") ctx.APIError(http.StatusConflict, "rebase failed because of conflict")
return return
} }
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
@ -1423,7 +1423,7 @@ func GetPullRequestCommits(ctx *context.APIContext) {
if issues_model.IsErrPullRequestNotExist(err) { if issues_model.IsErrPullRequestNotExist(err) {
ctx.APIErrorNotFound() ctx.APIErrorNotFound()
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }
@ -1546,7 +1546,7 @@ func GetPullRequestFiles(ctx *context.APIContext) {
if issues_model.IsErrPullRequestNotExist(err) { if issues_model.IsErrPullRequestNotExist(err) {
ctx.APIErrorNotFound() ctx.APIErrorNotFound()
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }

View File

@ -66,18 +66,18 @@ func ListPullReviews(ctx *context.APIContext) {
if issues_model.IsErrPullRequestNotExist(err) { if issues_model.IsErrPullRequestNotExist(err) {
ctx.APIErrorNotFound("GetPullRequestByIndex", err) ctx.APIErrorNotFound("GetPullRequestByIndex", err)
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }
if err = pr.LoadIssue(ctx); err != nil { if err = pr.LoadIssue(ctx); err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
if err = pr.Issue.LoadRepo(ctx); err != nil { if err = pr.Issue.LoadRepo(ctx); err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
@ -100,7 +100,7 @@ func ListPullReviews(ctx *context.APIContext) {
apiReviews, err := convert.ToPullReviewList(ctx, allReviews, ctx.Doer) apiReviews, err := convert.ToPullReviewList(ctx, allReviews, ctx.Doer)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
@ -151,7 +151,7 @@ func GetPullReview(ctx *context.APIContext) {
apiReview, err := convert.ToPullReview(ctx, review, ctx.Doer) apiReview, err := convert.ToPullReview(ctx, review, ctx.Doer)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
@ -201,7 +201,7 @@ func GetPullReviewComments(ctx *context.APIContext) {
apiComments, err := convert.ToPullReviewCommentList(ctx, review, ctx.Doer) apiComments, err := convert.ToPullReviewCommentList(ctx, review, ctx.Doer)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
@ -261,7 +261,7 @@ func DeletePullReview(ctx *context.APIContext) {
} }
if err := issues_model.DeleteReview(ctx, review); err != nil { if err := issues_model.DeleteReview(ctx, review); err != nil {
ctx.APIError(http.StatusInternalServerError, fmt.Errorf("can not delete ReviewID: %d", review.ID)) ctx.APIErrorInternal(fmt.Errorf("can not delete ReviewID: %d", review.ID))
return return
} }
@ -311,7 +311,7 @@ func CreatePullReview(ctx *context.APIContext) {
if issues_model.IsErrPullRequestNotExist(err) { if issues_model.IsErrPullRequestNotExist(err) {
ctx.APIErrorNotFound("GetPullRequestByIndex", err) ctx.APIErrorNotFound("GetPullRequestByIndex", err)
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }
@ -323,7 +323,7 @@ func CreatePullReview(ctx *context.APIContext) {
} }
if err := pr.Issue.LoadRepo(ctx); err != nil { if err := pr.Issue.LoadRepo(ctx); err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
@ -331,14 +331,14 @@ func CreatePullReview(ctx *context.APIContext) {
if opts.CommitID == "" { if opts.CommitID == "" {
gitRepo, closer, err := gitrepo.RepositoryFromContextOrOpen(ctx, pr.Issue.Repo) gitRepo, closer, err := gitrepo.RepositoryFromContextOrOpen(ctx, pr.Issue.Repo)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
defer closer.Close() defer closer.Close()
headCommitID, err := gitRepo.GetRefCommitID(pr.GetGitRefName()) headCommitID, err := gitRepo.GetRefCommitID(pr.GetGitRefName())
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
@ -364,7 +364,7 @@ func CreatePullReview(ctx *context.APIContext) {
opts.CommitID, opts.CommitID,
nil, nil,
); err != nil { ); err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
} }
@ -375,7 +375,7 @@ func CreatePullReview(ctx *context.APIContext) {
if errors.Is(err, pull_service.ErrSubmitReviewOnClosedPR) { if errors.Is(err, pull_service.ErrSubmitReviewOnClosedPR) {
ctx.APIError(http.StatusUnprocessableEntity, err) ctx.APIError(http.StatusUnprocessableEntity, err)
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }
@ -383,7 +383,7 @@ func CreatePullReview(ctx *context.APIContext) {
// convert response // convert response
apiReview, err := convert.ToPullReview(ctx, review, ctx.Doer) apiReview, err := convert.ToPullReview(ctx, review, ctx.Doer)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
ctx.JSON(http.StatusOK, apiReview) ctx.JSON(http.StatusOK, apiReview)
@ -457,7 +457,7 @@ func SubmitPullReview(ctx *context.APIContext) {
headCommitID, err := ctx.Repo.GitRepo.GetRefCommitID(pr.GetGitRefName()) headCommitID, err := ctx.Repo.GitRepo.GetRefCommitID(pr.GetGitRefName())
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
@ -467,7 +467,7 @@ func SubmitPullReview(ctx *context.APIContext) {
if errors.Is(err, pull_service.ErrSubmitReviewOnClosedPR) { if errors.Is(err, pull_service.ErrSubmitReviewOnClosedPR) {
ctx.APIError(http.StatusUnprocessableEntity, err) ctx.APIError(http.StatusUnprocessableEntity, err)
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }
@ -475,7 +475,7 @@ func SubmitPullReview(ctx *context.APIContext) {
// convert response // convert response
apiReview, err := convert.ToPullReview(ctx, review, ctx.Doer) apiReview, err := convert.ToPullReview(ctx, review, ctx.Doer)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
ctx.JSON(http.StatusOK, apiReview) ctx.JSON(http.StatusOK, apiReview)
@ -484,7 +484,7 @@ func SubmitPullReview(ctx *context.APIContext) {
// preparePullReviewType return ReviewType and false or nil and true if an error happen // preparePullReviewType return ReviewType and false or nil and true if an error happen
func preparePullReviewType(ctx *context.APIContext, pr *issues_model.PullRequest, event api.ReviewStateType, body string, hasComments bool) (issues_model.ReviewType, bool) { func preparePullReviewType(ctx *context.APIContext, pr *issues_model.PullRequest, event api.ReviewStateType, body string, hasComments bool) (issues_model.ReviewType, bool) {
if err := pr.LoadIssue(ctx); err != nil { if err := pr.LoadIssue(ctx); err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return -1, true return -1, true
} }
@ -538,7 +538,7 @@ func prepareSingleReview(ctx *context.APIContext) (*issues_model.Review, *issues
if issues_model.IsErrPullRequestNotExist(err) { if issues_model.IsErrPullRequestNotExist(err) {
ctx.APIErrorNotFound("GetPullRequestByIndex", err) ctx.APIErrorNotFound("GetPullRequestByIndex", err)
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return nil, nil, true return nil, nil, true
} }
@ -548,7 +548,7 @@ func prepareSingleReview(ctx *context.APIContext) (*issues_model.Review, *issues
if issues_model.IsErrReviewNotExist(err) { if issues_model.IsErrReviewNotExist(err) {
ctx.APIErrorNotFound("GetReviewByID", err) ctx.APIErrorNotFound("GetReviewByID", err)
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return nil, nil, true return nil, nil, true
} }
@ -566,7 +566,7 @@ func prepareSingleReview(ctx *context.APIContext) (*issues_model.Review, *issues
} }
if err := review.LoadAttributes(ctx); err != nil && !user_model.IsErrUserNotExist(err) { if err := review.LoadAttributes(ctx); err != nil && !user_model.IsErrUserNotExist(err) {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return nil, nil, true return nil, nil, true
} }
@ -671,7 +671,7 @@ func parseReviewersByNames(ctx *context.APIContext, reviewerNames, teamReviewerN
ctx.APIErrorNotFound("UserNotExist", fmt.Sprintf("User '%s' not exist", r)) ctx.APIErrorNotFound("UserNotExist", fmt.Sprintf("User '%s' not exist", r))
return nil, nil return nil, nil
} }
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return nil, nil return nil, nil
} }
@ -687,7 +687,7 @@ func parseReviewersByNames(ctx *context.APIContext, reviewerNames, teamReviewerN
ctx.APIErrorNotFound("TeamNotExist", fmt.Sprintf("Team '%s' not exist", t)) ctx.APIErrorNotFound("TeamNotExist", fmt.Sprintf("Team '%s' not exist", t))
return nil, nil return nil, nil
} }
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return nil, nil return nil, nil
} }
@ -703,19 +703,19 @@ func apiReviewRequest(ctx *context.APIContext, opts api.PullReviewRequestOptions
if issues_model.IsErrPullRequestNotExist(err) { if issues_model.IsErrPullRequestNotExist(err) {
ctx.APIErrorNotFound("GetPullRequestByIndex", err) ctx.APIErrorNotFound("GetPullRequestByIndex", err)
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }
if err := pr.Issue.LoadRepo(ctx); err != nil { if err := pr.Issue.LoadRepo(ctx); err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
permDoer, err := access_model.GetUserRepoPermission(ctx, pr.Issue.Repo, ctx.Doer) permDoer, err := access_model.GetUserRepoPermission(ctx, pr.Issue.Repo, ctx.Doer)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
@ -740,7 +740,7 @@ func apiReviewRequest(ctx *context.APIContext, opts api.PullReviewRequestOptions
ctx.APIError(http.StatusUnprocessableEntity, err) ctx.APIError(http.StatusUnprocessableEntity, err)
return return
} }
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
@ -782,7 +782,7 @@ func apiReviewRequest(ctx *context.APIContext, opts api.PullReviewRequestOptions
if isAdd { if isAdd {
apiReviews, err := convert.ToPullReviewList(ctx, reviews, ctx.Doer) apiReviews, err := convert.ToPullReviewList(ctx, reviews, ctx.Doer)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
ctx.JSON(http.StatusCreated, apiReviews) ctx.JSON(http.StatusCreated, apiReviews)
@ -903,19 +903,19 @@ func dismissReview(ctx *context.APIContext, msg string, isDismiss, dismissPriors
ctx.APIError(http.StatusForbidden, err) ctx.APIError(http.StatusForbidden, err)
return return
} }
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
if review, err = issues_model.GetReviewByID(ctx, review.ID); err != nil { if review, err = issues_model.GetReviewByID(ctx, review.ID); err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
// convert response // convert response
apiReview, err := convert.ToPullReview(ctx, review, ctx.Doer) apiReview, err := convert.ToPullReview(ctx, review, ctx.Doer)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
ctx.JSON(http.StatusOK, apiReview) ctx.JSON(http.StatusOK, apiReview)

View File

@ -53,7 +53,7 @@ func GetRelease(ctx *context.APIContext) {
id := ctx.PathParamInt64("id") id := ctx.PathParamInt64("id")
release, err := repo_model.GetReleaseForRepoByID(ctx, ctx.Repo.Repository.ID, id) release, err := repo_model.GetReleaseForRepoByID(ctx, ctx.Repo.Repository.ID, id)
if err != nil && !repo_model.IsErrReleaseNotExist(err) { if err != nil && !repo_model.IsErrReleaseNotExist(err) {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
if err != nil && repo_model.IsErrReleaseNotExist(err) || release.IsTag { if err != nil && repo_model.IsErrReleaseNotExist(err) || release.IsTag {
@ -62,7 +62,7 @@ func GetRelease(ctx *context.APIContext) {
} }
if err := release.LoadAttributes(ctx); err != nil { if err := release.LoadAttributes(ctx); err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
ctx.JSON(http.StatusOK, convert.ToAPIRelease(ctx, ctx.Repo.Repository, release)) ctx.JSON(http.StatusOK, convert.ToAPIRelease(ctx, ctx.Repo.Repository, release))
@ -93,7 +93,7 @@ func GetLatestRelease(ctx *context.APIContext) {
// "$ref": "#/responses/notFound" // "$ref": "#/responses/notFound"
release, err := repo_model.GetLatestReleaseByRepoID(ctx, ctx.Repo.Repository.ID) release, err := repo_model.GetLatestReleaseByRepoID(ctx, ctx.Repo.Repository.ID)
if err != nil && !repo_model.IsErrReleaseNotExist(err) { if err != nil && !repo_model.IsErrReleaseNotExist(err) {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
if err != nil && repo_model.IsErrReleaseNotExist(err) || if err != nil && repo_model.IsErrReleaseNotExist(err) ||
@ -103,7 +103,7 @@ func GetLatestRelease(ctx *context.APIContext) {
} }
if err := release.LoadAttributes(ctx); err != nil { if err := release.LoadAttributes(ctx); err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
ctx.JSON(http.StatusOK, convert.ToAPIRelease(ctx, ctx.Repo.Repository, release)) ctx.JSON(http.StatusOK, convert.ToAPIRelease(ctx, ctx.Repo.Repository, release))
@ -161,13 +161,13 @@ func ListReleases(ctx *context.APIContext) {
releases, err := db.Find[repo_model.Release](ctx, opts) releases, err := db.Find[repo_model.Release](ctx, opts)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
rels := make([]*api.Release, len(releases)) rels := make([]*api.Release, len(releases))
for i, release := range releases { for i, release := range releases {
if err := release.LoadAttributes(ctx); err != nil { if err := release.LoadAttributes(ctx); err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
rels[i] = convert.ToAPIRelease(ctx, ctx.Repo.Repository, release) rels[i] = convert.ToAPIRelease(ctx, ctx.Repo.Repository, release)
@ -226,7 +226,7 @@ func CreateRelease(ctx *context.APIContext) {
rel, err := repo_model.GetRelease(ctx, ctx.Repo.Repository.ID, form.TagName) rel, err := repo_model.GetRelease(ctx, ctx.Repo.Repository.ID, form.TagName)
if err != nil { if err != nil {
if !repo_model.IsErrReleaseNotExist(err) { if !repo_model.IsErrReleaseNotExist(err) {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
// If target is not provided use default branch // If target is not provided use default branch
@ -254,7 +254,7 @@ func CreateRelease(ctx *context.APIContext) {
} else if git.IsErrNotExist(err) { } else if git.IsErrNotExist(err) {
ctx.APIError(http.StatusNotFound, fmt.Errorf("target \"%v\" not found: %w", rel.Target, err)) ctx.APIError(http.StatusNotFound, fmt.Errorf("target \"%v\" not found: %w", rel.Target, err))
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }
@ -275,7 +275,7 @@ func CreateRelease(ctx *context.APIContext) {
rel.Target = form.Target rel.Target = form.Target
if err = release_service.UpdateRelease(ctx, ctx.Doer, ctx.Repo.GitRepo, rel, nil, nil, nil); err != nil { if err = release_service.UpdateRelease(ctx, ctx.Doer, ctx.Repo.GitRepo, rel, nil, nil, nil); err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
} }
@ -322,7 +322,7 @@ func EditRelease(ctx *context.APIContext) {
id := ctx.PathParamInt64("id") id := ctx.PathParamInt64("id")
rel, err := repo_model.GetReleaseForRepoByID(ctx, ctx.Repo.Repository.ID, id) rel, err := repo_model.GetReleaseForRepoByID(ctx, ctx.Repo.Repository.ID, id)
if err != nil && !repo_model.IsErrReleaseNotExist(err) { if err != nil && !repo_model.IsErrReleaseNotExist(err) {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
if err != nil && repo_model.IsErrReleaseNotExist(err) || rel.IsTag { if err != nil && repo_model.IsErrReleaseNotExist(err) || rel.IsTag {
@ -349,18 +349,18 @@ func EditRelease(ctx *context.APIContext) {
rel.IsPrerelease = *form.IsPrerelease rel.IsPrerelease = *form.IsPrerelease
} }
if err := release_service.UpdateRelease(ctx, ctx.Doer, ctx.Repo.GitRepo, rel, nil, nil, nil); err != nil { if err := release_service.UpdateRelease(ctx, ctx.Doer, ctx.Repo.GitRepo, rel, nil, nil, nil); err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
// reload data from database // reload data from database
rel, err = repo_model.GetReleaseByID(ctx, id) rel, err = repo_model.GetReleaseByID(ctx, id)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
if err := rel.LoadAttributes(ctx); err != nil { if err := rel.LoadAttributes(ctx); err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
ctx.JSON(http.StatusOK, convert.ToAPIRelease(ctx, ctx.Repo.Repository, rel)) ctx.JSON(http.StatusOK, convert.ToAPIRelease(ctx, ctx.Repo.Repository, rel))
@ -399,7 +399,7 @@ func DeleteRelease(ctx *context.APIContext) {
id := ctx.PathParamInt64("id") id := ctx.PathParamInt64("id")
rel, err := repo_model.GetReleaseForRepoByID(ctx, ctx.Repo.Repository.ID, id) rel, err := repo_model.GetReleaseForRepoByID(ctx, ctx.Repo.Repository.ID, id)
if err != nil && !repo_model.IsErrReleaseNotExist(err) { if err != nil && !repo_model.IsErrReleaseNotExist(err) {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
if err != nil && repo_model.IsErrReleaseNotExist(err) || rel.IsTag { if err != nil && repo_model.IsErrReleaseNotExist(err) || rel.IsTag {
@ -411,7 +411,7 @@ func DeleteRelease(ctx *context.APIContext) {
ctx.APIError(http.StatusUnprocessableEntity, "user not allowed to delete protected tag") ctx.APIError(http.StatusUnprocessableEntity, "user not allowed to delete protected tag")
return return
} }
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
ctx.Status(http.StatusNoContent) ctx.Status(http.StatusNoContent)

View File

@ -26,7 +26,7 @@ func checkReleaseMatchRepo(ctx *context.APIContext, releaseID int64) bool {
ctx.APIErrorNotFound() ctx.APIErrorNotFound()
return false return false
} }
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return false return false
} }
if release.RepoID != ctx.Repo.Repository.ID { if release.RepoID != ctx.Repo.Repository.ID {
@ -84,7 +84,7 @@ func GetReleaseAttachment(ctx *context.APIContext) {
ctx.APIErrorNotFound() ctx.APIErrorNotFound()
return return
} }
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
if attach.ReleaseID != releaseID { if attach.ReleaseID != releaseID {
@ -133,7 +133,7 @@ func ListReleaseAttachments(ctx *context.APIContext) {
ctx.APIErrorNotFound() ctx.APIErrorNotFound()
return return
} }
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
if release.RepoID != ctx.Repo.Repository.ID { if release.RepoID != ctx.Repo.Repository.ID {
@ -141,7 +141,7 @@ func ListReleaseAttachments(ctx *context.APIContext) {
return return
} }
if err := release.LoadAttributes(ctx); err != nil { if err := release.LoadAttributes(ctx); err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
ctx.JSON(http.StatusOK, convert.ToAPIRelease(ctx, ctx.Repo.Repository, release).Attachments) ctx.JSON(http.StatusOK, convert.ToAPIRelease(ctx, ctx.Repo.Repository, release).Attachments)
@ -212,7 +212,7 @@ func CreateReleaseAttachment(ctx *context.APIContext) {
if strings.HasPrefix(strings.ToLower(ctx.Req.Header.Get("Content-Type")), "multipart/form-data") { if strings.HasPrefix(strings.ToLower(ctx.Req.Header.Get("Content-Type")), "multipart/form-data") {
file, header, err := ctx.Req.FormFile("attachment") file, header, err := ctx.Req.FormFile("attachment")
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
defer file.Close() defer file.Close()
@ -245,7 +245,7 @@ func CreateReleaseAttachment(ctx *context.APIContext) {
ctx.APIError(http.StatusBadRequest, err) ctx.APIError(http.StatusBadRequest, err)
return return
} }
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
@ -311,7 +311,7 @@ func EditReleaseAttachment(ctx *context.APIContext) {
ctx.APIErrorNotFound() ctx.APIErrorNotFound()
return return
} }
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
if attach.ReleaseID != releaseID { if attach.ReleaseID != releaseID {
@ -329,7 +329,7 @@ func EditReleaseAttachment(ctx *context.APIContext) {
ctx.APIError(http.StatusUnprocessableEntity, err) ctx.APIError(http.StatusUnprocessableEntity, err)
return return
} }
ctx.APIError(http.StatusInternalServerError, attach) ctx.APIErrorInternal(err)
return return
} }
ctx.JSON(http.StatusCreated, convert.ToAPIAttachment(ctx.Repo.Repository, attach)) ctx.JSON(http.StatusCreated, convert.ToAPIAttachment(ctx.Repo.Repository, attach))
@ -384,7 +384,7 @@ func DeleteReleaseAttachment(ctx *context.APIContext) {
ctx.APIErrorNotFound() ctx.APIErrorNotFound()
return return
} }
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
if attach.ReleaseID != releaseID { if attach.ReleaseID != releaseID {
@ -395,7 +395,7 @@ func DeleteReleaseAttachment(ctx *context.APIContext) {
// FIXME Should prove the existence of the given repo, but results in unnecessary database requests // FIXME Should prove the existence of the given repo, but results in unnecessary database requests
if err := repo_model.DeleteAttachment(ctx, attach, true); err != nil { if err := repo_model.DeleteAttachment(ctx, attach, true); err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
ctx.Status(http.StatusNoContent) ctx.Status(http.StatusNoContent)

View File

@ -49,7 +49,7 @@ func GetReleaseByTag(ctx *context.APIContext) {
ctx.APIErrorNotFound() ctx.APIErrorNotFound()
return return
} }
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
@ -59,7 +59,7 @@ func GetReleaseByTag(ctx *context.APIContext) {
} }
if err = release.LoadAttributes(ctx); err != nil { if err = release.LoadAttributes(ctx); err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
ctx.JSON(http.StatusOK, convert.ToAPIRelease(ctx, ctx.Repo.Repository, release)) ctx.JSON(http.StatusOK, convert.ToAPIRelease(ctx, ctx.Repo.Repository, release))
@ -102,7 +102,7 @@ func DeleteReleaseByTag(ctx *context.APIContext) {
ctx.APIErrorNotFound() ctx.APIErrorNotFound()
return return
} }
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
@ -116,7 +116,7 @@ func DeleteReleaseByTag(ctx *context.APIContext) {
ctx.APIError(http.StatusUnprocessableEntity, "user not allowed to delete protected tag") ctx.APIError(http.StatusUnprocessableEntity, "user not allowed to delete protected tag")
return return
} }
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }

View File

@ -271,7 +271,7 @@ func CreateUserRepo(ctx *context.APIContext, owner *user_model.User, opt api.Cre
label.IsErrTemplateLoad(err) { label.IsErrTemplateLoad(err) {
ctx.APIError(http.StatusUnprocessableEntity, err) ctx.APIError(http.StatusUnprocessableEntity, err)
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }
@ -279,7 +279,7 @@ func CreateUserRepo(ctx *context.APIContext, owner *user_model.User, opt api.Cre
// reload repo from db to get a real state after creation // reload repo from db to get a real state after creation
repo, err = repo_model.GetRepositoryByID(ctx, repo.ID) repo, err = repo_model.GetRepositoryByID(ctx, repo.ID)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
ctx.JSON(http.StatusCreated, convert.ToRepo(ctx, repo, access_model.Permission{AccessMode: perm.AccessModeOwner})) ctx.JSON(http.StatusCreated, convert.ToRepo(ctx, repo, access_model.Permission{AccessMode: perm.AccessModeOwner}))
@ -395,7 +395,7 @@ func Generate(ctx *context.APIContext) {
return return
} }
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
@ -424,7 +424,7 @@ func Generate(ctx *context.APIContext) {
db.IsErrNamePatternNotAllowed(err) { db.IsErrNamePatternNotAllowed(err) {
ctx.APIError(http.StatusUnprocessableEntity, err) ctx.APIError(http.StatusUnprocessableEntity, err)
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }
@ -500,7 +500,7 @@ func CreateOrgRepo(ctx *context.APIContext) {
if organization.IsErrOrgNotExist(err) { if organization.IsErrOrgNotExist(err) {
ctx.APIError(http.StatusUnprocessableEntity, err) ctx.APIError(http.StatusUnprocessableEntity, err)
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }
@ -513,7 +513,7 @@ func CreateOrgRepo(ctx *context.APIContext) {
if !ctx.Doer.IsAdmin { if !ctx.Doer.IsAdmin {
canCreate, err := org.CanCreateOrgRepo(ctx, ctx.Doer.ID) canCreate, err := org.CanCreateOrgRepo(ctx, ctx.Doer.ID)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} else if !canCreate { } else if !canCreate {
ctx.APIError(http.StatusForbidden, "Given user is not allowed to create repository in organization.") ctx.APIError(http.StatusForbidden, "Given user is not allowed to create repository in organization.")
@ -548,7 +548,7 @@ func Get(ctx *context.APIContext) {
// "$ref": "#/responses/notFound" // "$ref": "#/responses/notFound"
if err := ctx.Repo.Repository.LoadAttributes(ctx); err != nil { if err := ctx.Repo.Repository.LoadAttributes(ctx); err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
@ -580,14 +580,14 @@ func GetByID(ctx *context.APIContext) {
if repo_model.IsErrRepoNotExist(err) { if repo_model.IsErrRepoNotExist(err) {
ctx.APIErrorNotFound() ctx.APIErrorNotFound()
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }
permission, err := access_model.GetUserRepoPermission(ctx, repo, ctx.Doer) permission, err := access_model.GetUserRepoPermission(ctx, repo, ctx.Doer)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} else if !permission.HasAnyUnitAccess() { } else if !permission.HasAnyUnitAccess() {
ctx.APIErrorNotFound() ctx.APIErrorNotFound()
@ -703,7 +703,7 @@ func updateBasicProperties(ctx *context.APIContext, opts api.EditRepoOption) err
// Visibility of forked repository is forced sync with base repository. // Visibility of forked repository is forced sync with base repository.
if repo.IsFork { if repo.IsFork {
if err := repo.GetBaseRepo(ctx); err != nil { if err := repo.GetBaseRepo(ctx); err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return err return err
} }
*opts.Private = repo.BaseRepo.IsPrivate *opts.Private = repo.BaseRepo.IsPrivate
@ -728,7 +728,7 @@ func updateBasicProperties(ctx *context.APIContext, opts api.EditRepoOption) err
var err error var err error
ctx.Repo.GitRepo, err = gitrepo.RepositoryFromRequestContextOrOpen(ctx, repo) ctx.Repo.GitRepo, err = gitrepo.RepositoryFromRequestContextOrOpen(ctx, repo)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return err return err
} }
} }
@ -738,7 +738,7 @@ func updateBasicProperties(ctx *context.APIContext, opts api.EditRepoOption) err
if opts.DefaultBranch != nil && repo.DefaultBranch != *opts.DefaultBranch && (repo.IsEmpty || ctx.Repo.GitRepo.IsBranchExist(*opts.DefaultBranch)) { if opts.DefaultBranch != nil && repo.DefaultBranch != *opts.DefaultBranch && (repo.IsEmpty || ctx.Repo.GitRepo.IsBranchExist(*opts.DefaultBranch)) {
if !repo.IsEmpty { if !repo.IsEmpty {
if err := gitrepo.SetDefaultBranch(ctx, ctx.Repo.Repository, *opts.DefaultBranch); err != nil { if err := gitrepo.SetDefaultBranch(ctx, ctx.Repo.Repository, *opts.DefaultBranch); err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return err return err
} }
updateRepoLicense = true updateRepoLicense = true
@ -747,7 +747,7 @@ func updateBasicProperties(ctx *context.APIContext, opts api.EditRepoOption) err
} }
if err := repo_service.UpdateRepository(ctx, repo, visibilityChanged); err != nil { if err := repo_service.UpdateRepository(ctx, repo, visibilityChanged); err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return err return err
} }
@ -755,7 +755,7 @@ func updateBasicProperties(ctx *context.APIContext, opts api.EditRepoOption) err
if err := repo_service.AddRepoToLicenseUpdaterQueue(&repo_service.LicenseUpdaterOptions{ if err := repo_service.AddRepoToLicenseUpdaterQueue(&repo_service.LicenseUpdaterOptions{
RepoID: ctx.Repo.Repository.ID, RepoID: ctx.Repo.Repository.ID,
}); err != nil { }); err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return err return err
} }
} }
@ -1024,7 +1024,7 @@ func updateRepoUnits(ctx *context.APIContext, opts api.EditRepoOption) error {
if len(units)+len(deleteUnitTypes) > 0 { if len(units)+len(deleteUnitTypes) > 0 {
if err := repo_service.UpdateRepositoryUnits(ctx, repo, units, deleteUnitTypes); err != nil { if err := repo_service.UpdateRepositoryUnits(ctx, repo, units, deleteUnitTypes); err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return err return err
} }
} }
@ -1046,7 +1046,7 @@ func updateRepoArchivedState(ctx *context.APIContext, opts api.EditRepoOption) e
if *opts.Archived { if *opts.Archived {
if err := repo_model.SetArchiveRepoState(ctx, repo, *opts.Archived); err != nil { if err := repo_model.SetArchiveRepoState(ctx, repo, *opts.Archived); err != nil {
log.Error("Tried to archive a repo: %s", err) log.Error("Tried to archive a repo: %s", err)
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return err return err
} }
if err := actions_model.CleanRepoScheduleTasks(ctx, repo); err != nil { if err := actions_model.CleanRepoScheduleTasks(ctx, repo); err != nil {
@ -1056,7 +1056,7 @@ func updateRepoArchivedState(ctx *context.APIContext, opts api.EditRepoOption) e
} else { } else {
if err := repo_model.SetArchiveRepoState(ctx, repo, *opts.Archived); err != nil { if err := repo_model.SetArchiveRepoState(ctx, repo, *opts.Archived); err != nil {
log.Error("Tried to un-archive a repo: %s", err) log.Error("Tried to un-archive a repo: %s", err)
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return err return err
} }
if ctx.Repo.Repository.UnitEnabled(ctx, unit_model.TypeActions) { if ctx.Repo.Repository.UnitEnabled(ctx, unit_model.TypeActions) {
@ -1084,7 +1084,7 @@ func updateMirror(ctx *context.APIContext, opts api.EditRepoOption) error {
mirror, err := repo_model.GetMirrorByRepoID(ctx, repo.ID) mirror, err := repo_model.GetMirrorByRepoID(ctx, repo.ID)
if err != nil { if err != nil {
log.Error("Failed to get mirror: %s", err) log.Error("Failed to get mirror: %s", err)
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return err return err
} }
@ -1158,7 +1158,7 @@ func Delete(ctx *context.APIContext) {
canDelete, err := repo_module.CanUserDelete(ctx, repo, ctx.Doer) canDelete, err := repo_module.CanUserDelete(ctx, repo, ctx.Doer)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} else if !canDelete { } else if !canDelete {
ctx.APIError(http.StatusForbidden, "Given user is not owner of organization.") ctx.APIError(http.StatusForbidden, "Given user is not owner of organization.")
@ -1170,7 +1170,7 @@ func Delete(ctx *context.APIContext) {
} }
if err := repo_service.DeleteRepository(ctx, ctx.Doer, repo, true); err != nil { if err := repo_service.DeleteRepository(ctx, ctx.Doer, repo, true); err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
@ -1315,7 +1315,7 @@ func ListRepoActivityFeeds(ctx *context.APIContext) {
feeds, count, err := feed_service.GetFeeds(ctx, opts) feeds, count, err := feed_service.GetFeeds(ctx, opts)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
ctx.SetTotalCountHeader(count) ctx.SetTotalCountHeader(count)

View File

@ -49,7 +49,7 @@ func ListStargazers(ctx *context.APIContext) {
stargazers, err := repo_model.GetStargazers(ctx, ctx.Repo.Repository, utils.GetListOptions(ctx)) stargazers, err := repo_model.GetStargazers(ctx, ctx.Repo.Repository, utils.GetListOptions(ctx))
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
users := make([]*api.User, len(stargazers)) users := make([]*api.User, len(stargazers))

View File

@ -65,7 +65,7 @@ func NewCommitStatus(ctx *context.APIContext) {
Context: form.Context, Context: form.Context,
} }
if err := commitstatus_service.CreateCommitStatus(ctx, ctx.Repo.Repository, ctx.Doer, sha, status); err != nil { if err := commitstatus_service.CreateCommitStatus(ctx, ctx.Repo.Repository, ctx.Doer, sha, status); err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
@ -203,7 +203,7 @@ func getCommitStatuses(ctx *context.APIContext, sha string) {
State: ctx.FormTrim("state"), State: ctx.FormTrim("state"),
}) })
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, fmt.Errorf("GetCommitStatuses[%s, %s, %d]: %w", repo.FullName(), sha, ctx.FormInt("page"), err)) ctx.APIErrorInternal(fmt.Errorf("GetCommitStatuses[%s, %s, %d]: %w", repo.FullName(), sha, ctx.FormInt("page"), err))
return return
} }
@ -266,7 +266,7 @@ func GetCombinedCommitStatusByRef(ctx *context.APIContext) {
statuses, count, err := git_model.GetLatestCommitStatus(ctx, repo.ID, sha, utils.GetListOptions(ctx)) statuses, count, err := git_model.GetLatestCommitStatus(ctx, repo.ID, sha, utils.GetListOptions(ctx))
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, fmt.Errorf("GetLatestCommitStatus[%s, %s]: %w", repo.FullName(), sha, err)) ctx.APIErrorInternal(fmt.Errorf("GetLatestCommitStatus[%s, %s]: %w", repo.FullName(), sha, err))
return return
} }

View File

@ -47,7 +47,7 @@ func ListSubscribers(ctx *context.APIContext) {
subscribers, err := repo_model.GetRepoWatchers(ctx, ctx.Repo.Repository.ID, utils.GetListOptions(ctx)) subscribers, err := repo_model.GetRepoWatchers(ctx, ctx.Repo.Repository.ID, utils.GetListOptions(ctx))
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
users := make([]*api.User, len(subscribers)) users := make([]*api.User, len(subscribers))

View File

@ -57,7 +57,7 @@ func ListTags(ctx *context.APIContext) {
tags, total, err := ctx.Repo.GitRepo.GetTagInfos(listOpts.Page, listOpts.PageSize) tags, total, err := ctx.Repo.GitRepo.GetTagInfos(listOpts.Page, listOpts.PageSize)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
@ -270,7 +270,7 @@ func DeleteTag(ctx *context.APIContext) {
ctx.APIErrorNotFound() ctx.APIErrorNotFound()
return return
} }
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
@ -284,7 +284,7 @@ func DeleteTag(ctx *context.APIContext) {
ctx.APIError(http.StatusUnprocessableEntity, "user not allowed to delete protected tag") ctx.APIError(http.StatusUnprocessableEntity, "user not allowed to delete protected tag")
return return
} }
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
@ -316,7 +316,7 @@ func ListTagProtection(ctx *context.APIContext) {
repo := ctx.Repo.Repository repo := ctx.Repo.Repository
pts, err := git_model.GetProtectedTags(ctx, repo.ID) pts, err := git_model.GetProtectedTags(ctx, repo.ID)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
apiPts := make([]*api.TagProtection, len(pts)) apiPts := make([]*api.TagProtection, len(pts))
@ -360,7 +360,7 @@ func GetTagProtection(ctx *context.APIContext) {
id := ctx.PathParamInt64("id") id := ctx.PathParamInt64("id")
pt, err := git_model.GetProtectedTagByID(ctx, id) pt, err := git_model.GetProtectedTagByID(ctx, id)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
@ -424,7 +424,7 @@ func CreateTagProtection(ctx *context.APIContext) {
pt, err := git_model.GetProtectedTagByNamePattern(ctx, repo.ID, namePattern) pt, err := git_model.GetProtectedTagByNamePattern(ctx, repo.ID, namePattern)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} else if pt != nil { } else if pt != nil {
ctx.APIError(http.StatusForbidden, "Tag protection already exist") ctx.APIError(http.StatusForbidden, "Tag protection already exist")
@ -438,7 +438,7 @@ func CreateTagProtection(ctx *context.APIContext) {
ctx.APIError(http.StatusUnprocessableEntity, err) ctx.APIError(http.StatusUnprocessableEntity, err)
return return
} }
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
@ -449,7 +449,7 @@ func CreateTagProtection(ctx *context.APIContext) {
ctx.APIError(http.StatusUnprocessableEntity, err) ctx.APIError(http.StatusUnprocessableEntity, err)
return return
} }
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
} }
@ -461,18 +461,18 @@ func CreateTagProtection(ctx *context.APIContext) {
AllowlistTeamIDs: whitelistTeams, AllowlistTeamIDs: whitelistTeams,
} }
if err := git_model.InsertProtectedTag(ctx, protectTag); err != nil { if err := git_model.InsertProtectedTag(ctx, protectTag); err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
pt, err = git_model.GetProtectedTagByID(ctx, protectTag.ID) pt, err = git_model.GetProtectedTagByID(ctx, protectTag.ID)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
if pt == nil || pt.RepoID != repo.ID { if pt == nil || pt.RepoID != repo.ID {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
@ -524,7 +524,7 @@ func EditTagProtection(ctx *context.APIContext) {
id := ctx.PathParamInt64("id") id := ctx.PathParamInt64("id")
pt, err := git_model.GetProtectedTagByID(ctx, id) pt, err := git_model.GetProtectedTagByID(ctx, id)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
@ -546,7 +546,7 @@ func EditTagProtection(ctx *context.APIContext) {
ctx.APIError(http.StatusUnprocessableEntity, err) ctx.APIError(http.StatusUnprocessableEntity, err)
return return
} }
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
} }
@ -560,7 +560,7 @@ func EditTagProtection(ctx *context.APIContext) {
ctx.APIError(http.StatusUnprocessableEntity, err) ctx.APIError(http.StatusUnprocessableEntity, err)
return return
} }
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
pt.AllowlistUserIDs = whitelistUsers pt.AllowlistUserIDs = whitelistUsers
@ -568,18 +568,18 @@ func EditTagProtection(ctx *context.APIContext) {
err = git_model.UpdateProtectedTag(ctx, pt) err = git_model.UpdateProtectedTag(ctx, pt)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
pt, err = git_model.GetProtectedTagByID(ctx, id) pt, err = git_model.GetProtectedTagByID(ctx, id)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
if pt == nil || pt.RepoID != repo.ID { if pt == nil || pt.RepoID != repo.ID {
ctx.APIError(http.StatusInternalServerError, "New tag protection not found") ctx.APIErrorInternal(errors.New("new tag protection not found"))
return return
} }
@ -619,7 +619,7 @@ func DeleteTagProtection(ctx *context.APIContext) {
id := ctx.PathParamInt64("id") id := ctx.PathParamInt64("id")
pt, err := git_model.GetProtectedTagByID(ctx, id) pt, err := git_model.GetProtectedTagByID(ctx, id)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
@ -630,7 +630,7 @@ func DeleteTagProtection(ctx *context.APIContext) {
err = git_model.DeleteProtectedTag(ctx, pt) err = git_model.DeleteProtectedTag(ctx, pt)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }

View File

@ -170,7 +170,7 @@ func AcceptTransfer(ctx *context.APIContext) {
case errors.Is(err, util.ErrPermissionDenied): case errors.Is(err, util.ErrPermissionDenied):
ctx.APIError(http.StatusForbidden, err) ctx.APIError(http.StatusForbidden, err)
default: default:
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }
@ -212,7 +212,7 @@ func RejectTransfer(ctx *context.APIContext) {
case errors.Is(err, util.ErrPermissionDenied): case errors.Is(err, util.ErrPermissionDenied):
ctx.APIError(http.StatusForbidden, err) ctx.APIError(http.StatusForbidden, err)
default: default:
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }

View File

@ -82,7 +82,7 @@ func NewWikiPage(ctx *context.APIContext) {
} else if repo_model.IsErrWikiAlreadyExist(err) { } else if repo_model.IsErrWikiAlreadyExist(err) {
ctx.APIError(http.StatusBadRequest, err) ctx.APIError(http.StatusBadRequest, err)
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }
@ -155,7 +155,7 @@ func EditWikiPage(ctx *context.APIContext) {
form.ContentBase64 = string(content) form.ContentBase64 = string(content)
if err := wiki_service.EditWikiPage(ctx, ctx.Doer, ctx.Repo.Repository, oldWikiName, newWikiName, form.ContentBase64, form.Message); err != nil { if err := wiki_service.EditWikiPage(ctx, ctx.Doer, ctx.Repo.Repository, oldWikiName, newWikiName, form.ContentBase64, form.Message); err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
@ -198,7 +198,7 @@ func getWikiPage(ctx *context.APIContext, wikiName wiki_service.WebPath) *api.Wi
// Get last change information. // Get last change information.
lastCommit, err := wikiRepo.GetCommitByPath(pageFilename) lastCommit, err := wikiRepo.GetCommitByPath(pageFilename)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return nil return nil
} }
@ -249,7 +249,7 @@ func DeleteWikiPage(ctx *context.APIContext) {
ctx.APIErrorNotFound(err) ctx.APIErrorNotFound(err)
return return
} }
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
@ -322,7 +322,7 @@ func ListWikiPages(ctx *context.APIContext) {
} }
c, err := wikiRepo.GetCommitByPath(entry.Name()) c, err := wikiRepo.GetCommitByPath(entry.Name())
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
wikiName, err := wiki_service.GitPathToWebPath(entry.Name()) wikiName, err := wiki_service.GitPathToWebPath(entry.Name())
@ -330,7 +330,7 @@ func ListWikiPages(ctx *context.APIContext) {
if repo_model.IsErrWikiInvalidFileName(err) { if repo_model.IsErrWikiInvalidFileName(err) {
continue continue
} }
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
pages = append(pages, wiki_service.ToWikiPageMetaData(wikiName, c, ctx.Repo.Repository)) pages = append(pages, wiki_service.ToWikiPageMetaData(wikiName, c, ctx.Repo.Repository))
@ -447,7 +447,7 @@ func ListPageRevisions(ctx *context.APIContext) {
Page: page, Page: page,
}) })
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
@ -481,7 +481,7 @@ func findWikiRepoCommit(ctx *context.APIContext) (*git.Repository, *git.Commit)
if git.IsErrNotExist(err) || err.Error() == "no such file or directory" { if git.IsErrNotExist(err) || err.Error() == "no such file or directory" {
ctx.APIErrorNotFound(err) ctx.APIErrorNotFound(err)
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return nil, nil return nil, nil
} }
@ -491,7 +491,7 @@ func findWikiRepoCommit(ctx *context.APIContext) (*git.Repository, *git.Commit)
if git.IsErrNotExist(err) { if git.IsErrNotExist(err) {
ctx.APIErrorNotFound(err) ctx.APIErrorNotFound(err)
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return wikiRepo, nil return wikiRepo, nil
} }
@ -507,7 +507,7 @@ func wikiContentsByEntry(ctx *context.APIContext, entry *git.TreeEntry) string {
} }
content, err := blob.GetBlobContentBase64() content, err := blob.GetBlobContentBase64()
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return "" return ""
} }
return content return content

View File

@ -21,12 +21,12 @@ func ListBlocks(ctx *context.APIContext, blocker *user_model.User) {
BlockerID: blocker.ID, BlockerID: blocker.ID,
}) })
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
if err := user_model.BlockingList(blocks).LoadAttributes(ctx); err != nil { if err := user_model.BlockingList(blocks).LoadAttributes(ctx); err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
@ -49,7 +49,7 @@ func CheckUserBlock(ctx *context.APIContext, blocker *user_model.User) {
status := http.StatusNotFound status := http.StatusNotFound
blocking, err := user_model.GetBlocking(ctx, blocker.ID, blockee.ID) blocking, err := user_model.GetBlocking(ctx, blocker.ID, blockee.ID)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
if blocking != nil { if blocking != nil {
@ -70,7 +70,7 @@ func BlockUser(ctx *context.APIContext, blocker *user_model.User) {
if errors.Is(err, user_model.ErrCanNotBlock) || errors.Is(err, user_model.ErrBlockOrganization) { if errors.Is(err, user_model.ErrCanNotBlock) || errors.Is(err, user_model.ErrBlockOrganization) {
ctx.APIError(http.StatusBadRequest, err) ctx.APIError(http.StatusBadRequest, err)
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }
@ -89,7 +89,7 @@ func UnblockUser(ctx *context.APIContext, doer, blocker *user_model.User) {
if errors.Is(err, user_model.ErrCanNotUnblock) || errors.Is(err, user_model.ErrBlockOrganization) { if errors.Is(err, user_model.ErrCanNotUnblock) || errors.Is(err, user_model.ErrBlockOrganization) {
ctx.APIError(http.StatusBadRequest, err) ctx.APIError(http.StatusBadRequest, err)
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }

View File

@ -56,7 +56,7 @@ func CreateOrUpdateSecret(ctx *context.APIContext) {
} else if errors.Is(err, util.ErrNotExist) { } else if errors.Is(err, util.ErrNotExist) {
ctx.APIError(http.StatusNotFound, err) ctx.APIError(http.StatusNotFound, err)
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }
@ -98,7 +98,7 @@ func DeleteSecret(ctx *context.APIContext) {
} else if errors.Is(err, util.ErrNotExist) { } else if errors.Is(err, util.ErrNotExist) {
ctx.APIError(http.StatusNotFound, err) ctx.APIError(http.StatusNotFound, err)
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }
@ -145,7 +145,7 @@ func CreateVariable(ctx *context.APIContext) {
Name: variableName, Name: variableName,
}) })
if err != nil && !errors.Is(err, util.ErrNotExist) { if err != nil && !errors.Is(err, util.ErrNotExist) {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
if v != nil && v.ID > 0 { if v != nil && v.ID > 0 {
@ -157,7 +157,7 @@ func CreateVariable(ctx *context.APIContext) {
if errors.Is(err, util.ErrInvalidArgument) { if errors.Is(err, util.ErrInvalidArgument) {
ctx.APIError(http.StatusBadRequest, err) ctx.APIError(http.StatusBadRequest, err)
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }
@ -204,7 +204,7 @@ func UpdateVariable(ctx *context.APIContext) {
if errors.Is(err, util.ErrNotExist) { if errors.Is(err, util.ErrNotExist) {
ctx.APIError(http.StatusNotFound, err) ctx.APIError(http.StatusNotFound, err)
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }
@ -220,7 +220,7 @@ func UpdateVariable(ctx *context.APIContext) {
if errors.Is(err, util.ErrInvalidArgument) { if errors.Is(err, util.ErrInvalidArgument) {
ctx.APIError(http.StatusBadRequest, err) ctx.APIError(http.StatusBadRequest, err)
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }
@ -257,7 +257,7 @@ func DeleteVariable(ctx *context.APIContext) {
} else if errors.Is(err, util.ErrNotExist) { } else if errors.Is(err, util.ErrNotExist) {
ctx.APIError(http.StatusNotFound, err) ctx.APIError(http.StatusNotFound, err)
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }
@ -294,7 +294,7 @@ func GetVariable(ctx *context.APIContext) {
if errors.Is(err, util.ErrNotExist) { if errors.Is(err, util.ErrNotExist) {
ctx.APIError(http.StatusNotFound, err) ctx.APIError(http.StatusNotFound, err)
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }
@ -338,7 +338,7 @@ func ListVariables(ctx *context.APIContext) {
ListOptions: utils.GetListOptions(ctx), ListOptions: utils.GetListOptions(ctx),
}) })
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }

View File

@ -125,7 +125,7 @@ func CreateAccessToken(ctx *context.APIContext) {
t.Scope = scope t.Scope = scope
if err := auth_model.NewAccessToken(ctx, t); err != nil { if err := auth_model.NewAccessToken(ctx, t); err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
ctx.JSON(http.StatusCreated, &api.AccessToken{ ctx.JSON(http.StatusCreated, &api.AccessToken{
@ -174,7 +174,7 @@ func DeleteAccessToken(ctx *context.APIContext) {
UserID: ctx.ContextUser.ID, UserID: ctx.ContextUser.ID,
}) })
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
@ -190,7 +190,7 @@ func DeleteAccessToken(ctx *context.APIContext) {
} }
} }
if tokenID == 0 { if tokenID == 0 {
ctx.APIError(http.StatusInternalServerError, nil) ctx.APIErrorInternal(nil)
return return
} }
@ -198,7 +198,7 @@ func DeleteAccessToken(ctx *context.APIContext) {
if auth_model.IsErrAccessTokenNotExist(err) { if auth_model.IsErrAccessTokenNotExist(err) {
ctx.APIErrorNotFound() ctx.APIErrorNotFound()
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }
@ -273,7 +273,7 @@ func ListOauth2Applications(ctx *context.APIContext) {
OwnerID: ctx.Doer.ID, OwnerID: ctx.Doer.ID,
}) })
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
@ -311,7 +311,7 @@ func DeleteOauth2Application(ctx *context.APIContext) {
if auth_model.IsErrOAuthApplicationNotFound(err) { if auth_model.IsErrOAuthApplicationNotFound(err) {
ctx.APIErrorNotFound() ctx.APIErrorNotFound()
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }
@ -344,7 +344,7 @@ func GetOauth2Application(ctx *context.APIContext) {
if auth_model.IsErrOauthClientIDInvalid(err) || auth_model.IsErrOAuthApplicationNotFound(err) { if auth_model.IsErrOauthClientIDInvalid(err) || auth_model.IsErrOAuthApplicationNotFound(err) {
ctx.APIErrorNotFound() ctx.APIErrorNotFound()
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }
@ -398,7 +398,7 @@ func UpdateOauth2Application(ctx *context.APIContext) {
if auth_model.IsErrOauthClientIDInvalid(err) || auth_model.IsErrOAuthApplicationNotFound(err) { if auth_model.IsErrOauthClientIDInvalid(err) || auth_model.IsErrOAuthApplicationNotFound(err) {
ctx.APIErrorNotFound() ctx.APIErrorNotFound()
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }

View File

@ -38,7 +38,7 @@ func UpdateAvatar(ctx *context.APIContext) {
err = user_service.UploadAvatar(ctx, ctx.Doer, content) err = user_service.UploadAvatar(ctx, ctx.Doer, content)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
@ -57,7 +57,7 @@ func DeleteAvatar(ctx *context.APIContext) {
// "$ref": "#/responses/empty" // "$ref": "#/responses/empty"
err := user_service.DeleteAvatar(ctx, ctx.Doer) err := user_service.DeleteAvatar(ctx, ctx.Doer)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }

View File

@ -29,7 +29,7 @@ func ListEmails(ctx *context.APIContext) {
emails, err := user_model.GetEmailAddresses(ctx, ctx.Doer.ID) emails, err := user_model.GetEmailAddresses(ctx, ctx.Doer.ID)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
apiEmails := make([]*api.Email, len(emails)) apiEmails := make([]*api.Email, len(emails))
@ -78,14 +78,14 @@ func AddEmail(ctx *context.APIContext) {
errMsg := fmt.Sprintf("Email address %q invalid", email) errMsg := fmt.Sprintf("Email address %q invalid", email)
ctx.APIError(http.StatusUnprocessableEntity, errMsg) ctx.APIError(http.StatusUnprocessableEntity, errMsg)
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }
emails, err := user_model.GetEmailAddresses(ctx, ctx.Doer.ID) emails, err := user_model.GetEmailAddresses(ctx, ctx.Doer.ID)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
@ -124,7 +124,7 @@ func DeleteEmail(ctx *context.APIContext) {
if user_model.IsErrEmailAddressNotExist(err) { if user_model.IsErrEmailAddressNotExist(err) {
ctx.APIError(http.StatusNotFound, err) ctx.APIError(http.StatusNotFound, err)
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }

View File

@ -26,7 +26,7 @@ func responseAPIUsers(ctx *context.APIContext, users []*user_model.User) {
func listUserFollowers(ctx *context.APIContext, u *user_model.User) { func listUserFollowers(ctx *context.APIContext, u *user_model.User) {
users, count, err := user_model.GetUserFollowers(ctx, u, ctx.Doer, utils.GetListOptions(ctx)) users, count, err := user_model.GetUserFollowers(ctx, u, ctx.Doer, utils.GetListOptions(ctx))
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
@ -90,7 +90,7 @@ func ListFollowers(ctx *context.APIContext) {
func listUserFollowing(ctx *context.APIContext, u *user_model.User) { func listUserFollowing(ctx *context.APIContext, u *user_model.User) {
users, count, err := user_model.GetUserFollowing(ctx, u, ctx.Doer, utils.GetListOptions(ctx)) users, count, err := user_model.GetUserFollowing(ctx, u, ctx.Doer, utils.GetListOptions(ctx))
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
@ -231,7 +231,7 @@ func Follow(ctx *context.APIContext) {
if errors.Is(err, user_model.ErrBlockedUser) { if errors.Is(err, user_model.ErrBlockedUser) {
ctx.APIError(http.StatusForbidden, err) ctx.APIError(http.StatusForbidden, err)
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }
@ -256,7 +256,7 @@ func Unfollow(ctx *context.APIContext) {
// "$ref": "#/responses/notFound" // "$ref": "#/responses/notFound"
if err := user_model.UnfollowUser(ctx, ctx.Doer.ID, ctx.ContextUser.ID); err != nil { if err := user_model.UnfollowUser(ctx, ctx.Doer.ID, ctx.ContextUser.ID); err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
ctx.Status(http.StatusNoContent) ctx.Status(http.StatusNoContent)

View File

@ -25,12 +25,12 @@ func listGPGKeys(ctx *context.APIContext, uid int64, listOptions db.ListOptions)
OwnerID: uid, OwnerID: uid,
}) })
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
if err := asymkey_model.GPGKeyList(keys).LoadSubKeys(ctx); err != nil { if err := asymkey_model.GPGKeyList(keys).LoadSubKeys(ctx); err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
@ -121,12 +121,12 @@ func GetGPGKey(ctx *context.APIContext) {
if asymkey_model.IsErrGPGKeyNotExist(err) { if asymkey_model.IsErrGPGKeyNotExist(err) {
ctx.APIErrorNotFound() ctx.APIErrorNotFound()
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }
if err := key.LoadSubKeys(ctx); err != nil { if err := key.LoadSubKeys(ctx); err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
ctx.JSON(http.StatusOK, convert.ToGPGKey(key)) ctx.JSON(http.StatusOK, convert.ToGPGKey(key))
@ -208,7 +208,7 @@ func VerifyUserGPGKey(ctx *context.APIContext) {
ctx.APIError(http.StatusUnprocessableEntity, fmt.Sprintf("The provided GPG key, signature and token do not match or token is out of date. Provide a valid signature for the token: %s", token)) ctx.APIError(http.StatusUnprocessableEntity, fmt.Sprintf("The provided GPG key, signature and token do not match or token is out of date. Provide a valid signature for the token: %s", token))
return return
} }
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
keys, err := db.Find[asymkey_model.GPGKey](ctx, asymkey_model.FindGPGKeyOptions{ keys, err := db.Find[asymkey_model.GPGKey](ctx, asymkey_model.FindGPGKeyOptions{
@ -219,7 +219,7 @@ func VerifyUserGPGKey(ctx *context.APIContext) {
if asymkey_model.IsErrGPGKeyNotExist(err) { if asymkey_model.IsErrGPGKeyNotExist(err) {
ctx.APIErrorNotFound() ctx.APIErrorNotFound()
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }
@ -284,7 +284,7 @@ func DeleteGPGKey(ctx *context.APIContext) {
if asymkey_model.IsErrGPGKeyAccessDenied(err) { if asymkey_model.IsErrGPGKeyAccessDenied(err) {
ctx.APIError(http.StatusForbidden, "You do not have access to this key") ctx.APIError(http.StatusForbidden, "You do not have access to this key")
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }
@ -306,6 +306,6 @@ func HandleAddGPGKeyError(ctx *context.APIContext, err error, token string) {
case asymkey_model.IsErrGPGInvalidTokenSignature(err): case asymkey_model.IsErrGPGInvalidTokenSignature(err):
ctx.APIError(http.StatusUnprocessableEntity, fmt.Sprintf("The provided GPG key, signature and token do not match or token is out of date. Provide a valid signature for the token: %s", token)) ctx.APIError(http.StatusUnprocessableEntity, fmt.Sprintf("The provided GPG key, signature and token do not match or token is out of date. Provide a valid signature for the token: %s", token))
default: default:
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
} }

View File

@ -4,8 +4,6 @@
package user package user
import ( import (
"net/http"
user_model "code.gitea.io/gitea/models/user" user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/services/context" "code.gitea.io/gitea/services/context"
) )
@ -23,7 +21,7 @@ func GetUserByPathParam(ctx *context.APIContext, name string) *user_model.User {
ctx.APIErrorNotFound("GetUserByName", err) ctx.APIErrorNotFound("GetUserByName", err)
} }
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return nil return nil
} }

View File

@ -81,7 +81,7 @@ func listPublicKeys(ctx *context.APIContext, user *user_model.User) {
} }
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
@ -184,7 +184,7 @@ func GetPublicKey(ctx *context.APIContext) {
if asymkey_model.IsErrKeyNotExist(err) { if asymkey_model.IsErrKeyNotExist(err) {
ctx.APIErrorNotFound() ctx.APIErrorNotFound()
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }
@ -280,7 +280,7 @@ func DeletePublicKey(ctx *context.APIContext) {
if asymkey_model.IsErrKeyNotExist(err) { if asymkey_model.IsErrKeyNotExist(err) {
ctx.APIErrorNotFound() ctx.APIErrorNotFound()
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }
@ -294,7 +294,7 @@ func DeletePublicKey(ctx *context.APIContext) {
if asymkey_model.IsErrKeyAccessDenied(err) { if asymkey_model.IsErrKeyAccessDenied(err) {
ctx.APIError(http.StatusForbidden, "You do not have access to this key") ctx.APIError(http.StatusForbidden, "You do not have access to this key")
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }

View File

@ -26,12 +26,12 @@ func listUserRepos(ctx *context.APIContext, u *user_model.User, private bool) {
OrderBy: "id ASC", OrderBy: "id ASC",
}) })
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
if err := repos.LoadAttributes(ctx); err != nil { if err := repos.LoadAttributes(ctx); err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
@ -39,7 +39,7 @@ func listUserRepos(ctx *context.APIContext, u *user_model.User, private bool) {
for i := range repos { for i := range repos {
permission, err := access_model.GetUserRepoPermission(ctx, repos[i], ctx.Doer) permission, err := access_model.GetUserRepoPermission(ctx, repos[i], ctx.Doer)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
if ctx.IsSigned && ctx.Doer.IsAdmin || permission.HasAnyUnitAccess() { if ctx.IsSigned && ctx.Doer.IsAdmin || permission.HasAnyUnitAccess() {
@ -113,19 +113,19 @@ func ListMyRepos(ctx *context.APIContext) {
repos, count, err := repo_model.SearchRepository(ctx, opts) repos, count, err := repo_model.SearchRepository(ctx, opts)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
results := make([]*api.Repository, len(repos)) results := make([]*api.Repository, len(repos))
for i, repo := range repos { for i, repo := range repos {
if err = repo.LoadOwner(ctx); err != nil { if err = repo.LoadOwner(ctx); err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
permission, err := access_model.GetUserRepoPermission(ctx, repo, ctx.Doer) permission, err := access_model.GetUserRepoPermission(ctx, repo, ctx.Doer)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
results[i] = convert.ToRepo(ctx, repo, permission) results[i] = convert.ToRepo(ctx, repo, permission)
} }

View File

@ -72,7 +72,7 @@ func GetStarredRepos(ctx *context.APIContext) {
private := ctx.ContextUser.ID == ctx.Doer.ID private := ctx.ContextUser.ID == ctx.Doer.ID
repos, err := getStarredRepos(ctx, ctx.ContextUser, private) repos, err := getStarredRepos(ctx, ctx.ContextUser, private)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
@ -104,7 +104,7 @@ func GetMyStarredRepos(ctx *context.APIContext) {
repos, err := getStarredRepos(ctx, ctx.Doer, true) repos, err := getStarredRepos(ctx, ctx.Doer, true)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
ctx.SetTotalCountHeader(int64(ctx.Doer.NumStars)) ctx.SetTotalCountHeader(int64(ctx.Doer.NumStars))
@ -171,7 +171,7 @@ func Star(ctx *context.APIContext) {
if errors.Is(err, user_model.ErrBlockedUser) { if errors.Is(err, user_model.ErrBlockedUser) {
ctx.APIError(http.StatusForbidden, err) ctx.APIError(http.StatusForbidden, err)
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }
@ -204,7 +204,7 @@ func Unstar(ctx *context.APIContext) {
err := repo_model.StarRepo(ctx, ctx.Doer, ctx.Repo.Repository, false) err := repo_model.StarRepo(ctx, ctx.Doer, ctx.Repo.Repository, false)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
ctx.Status(http.StatusNoContent) ctx.Status(http.StatusNoContent)

View File

@ -162,7 +162,7 @@ func GetUserHeatmapData(ctx *context.APIContext) {
heatmap, err := activities_model.GetUserHeatmapDataByUser(ctx, ctx.ContextUser, ctx.Doer) heatmap, err := activities_model.GetUserHeatmapDataByUser(ctx, ctx.ContextUser, ctx.Doer)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
ctx.JSON(http.StatusOK, heatmap) ctx.JSON(http.StatusOK, heatmap)
@ -217,7 +217,7 @@ func ListUserActivityFeeds(ctx *context.APIContext) {
feeds, count, err := feed_service.GetFeeds(ctx, opts) feeds, count, err := feed_service.GetFeeds(ctx, opts)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
ctx.SetTotalCountHeader(count) ctx.SetTotalCountHeader(count)

View File

@ -68,7 +68,7 @@ func GetWatchedRepos(ctx *context.APIContext) {
private := ctx.ContextUser.ID == ctx.Doer.ID private := ctx.ContextUser.ID == ctx.Doer.ID
repos, total, err := getWatchedRepos(ctx, ctx.ContextUser, private) repos, total, err := getWatchedRepos(ctx, ctx.ContextUser, private)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
ctx.SetTotalCountHeader(total) ctx.SetTotalCountHeader(total)
@ -97,7 +97,7 @@ func GetMyWatchedRepos(ctx *context.APIContext) {
repos, total, err := getWatchedRepos(ctx, ctx.Doer, true) repos, total, err := getWatchedRepos(ctx, ctx.Doer, true)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
ctx.SetTotalCountHeader(total) ctx.SetTotalCountHeader(total)
@ -170,7 +170,7 @@ func Watch(ctx *context.APIContext) {
if errors.Is(err, user_model.ErrBlockedUser) { if errors.Is(err, user_model.ErrBlockedUser) {
ctx.APIError(http.StatusForbidden, err) ctx.APIError(http.StatusForbidden, err)
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }
@ -208,7 +208,7 @@ func Unwatch(ctx *context.APIContext) {
err := repo_model.WatchRepo(ctx, ctx.Doer, ctx.Repo.Repository, false) err := repo_model.WatchRepo(ctx, ctx.Doer, ctx.Repo.Repository, false)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
ctx.Status(http.StatusNoContent) ctx.Status(http.StatusNoContent)

View File

@ -26,7 +26,7 @@ func ResolveRefOrSha(ctx *context.APIContext, ref string) string {
for _, refType := range []string{"heads", "tags"} { for _, refType := range []string{"heads", "tags"} {
refSHA, lastMethodName, err := searchRefCommitByType(ctx, refType, ref) refSHA, lastMethodName, err := searchRefCommitByType(ctx, refType, ref)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, fmt.Errorf("%s: %w", lastMethodName, err)) ctx.APIErrorInternal(fmt.Errorf("%s: %w", lastMethodName, err))
return "" return ""
} }
if refSHA != "" { if refSHA != "" {

View File

@ -54,7 +54,7 @@ func GetOwnerHook(ctx *context.APIContext, ownerID, hookID int64) (*webhook.Webh
if webhook.IsErrWebhookNotExist(err) { if webhook.IsErrWebhookNotExist(err) {
ctx.APIErrorNotFound() ctx.APIErrorNotFound()
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return nil, err return nil, err
} }
@ -69,7 +69,7 @@ func GetRepoHook(ctx *context.APIContext, repoID, hookID int64) (*webhook.Webhoo
if webhook.IsErrWebhookNotExist(err) { if webhook.IsErrWebhookNotExist(err) {
ctx.APIErrorNotFound() ctx.APIErrorNotFound()
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return nil, err return nil, err
} }
@ -102,7 +102,7 @@ func AddSystemHook(ctx *context.APIContext, form *api.CreateHookOption) {
if ok { if ok {
h, err := webhook_service.ToHook(setting.AppSubURL+"/-/admin", hook) h, err := webhook_service.ToHook(setting.AppSubURL+"/-/admin", hook)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
ctx.JSON(http.StatusCreated, h) ctx.JSON(http.StatusCreated, h)
@ -141,7 +141,7 @@ func AddRepoHook(ctx *context.APIContext, form *api.CreateHookOption) {
func toAPIHook(ctx *context.APIContext, repoLink string, hook *webhook.Webhook) (*api.Hook, bool) { func toAPIHook(ctx *context.APIContext, repoLink string, hook *webhook.Webhook) (*api.Hook, bool) {
apiHook, err := webhook_service.ToHook(repoLink, hook) apiHook, err := webhook_service.ToHook(repoLink, hook)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return nil, false return nil, false
} }
return apiHook, true return apiHook, true
@ -215,7 +215,7 @@ func addHook(ctx *context.APIContext, form *api.CreateHookOption, ownerID, repoI
} }
err := w.SetHeaderAuthorization(form.AuthorizationHeader) err := w.SetHeaderAuthorization(form.AuthorizationHeader)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return nil, false return nil, false
} }
if w.Type == webhook_module.SLACK { if w.Type == webhook_module.SLACK {
@ -238,17 +238,17 @@ func addHook(ctx *context.APIContext, form *api.CreateHookOption, ownerID, repoI
Color: form.Config["color"], Color: form.Config["color"],
}) })
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return nil, false return nil, false
} }
w.Meta = string(meta) w.Meta = string(meta)
} }
if err := w.UpdateEvent(); err != nil { if err := w.UpdateEvent(); err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return nil, false return nil, false
} else if err := webhook.CreateWebhook(ctx, w); err != nil { } else if err := webhook.CreateWebhook(ctx, w); err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return nil, false return nil, false
} }
return w, true return w, true
@ -258,21 +258,21 @@ func addHook(ctx *context.APIContext, form *api.CreateHookOption, ownerID, repoI
func EditSystemHook(ctx *context.APIContext, form *api.EditHookOption, hookID int64) { func EditSystemHook(ctx *context.APIContext, form *api.EditHookOption, hookID int64) {
hook, err := webhook.GetSystemOrDefaultWebhook(ctx, hookID) hook, err := webhook.GetSystemOrDefaultWebhook(ctx, hookID)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
if !editHook(ctx, form, hook) { if !editHook(ctx, form, hook) {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
updated, err := webhook.GetSystemOrDefaultWebhook(ctx, hookID) updated, err := webhook.GetSystemOrDefaultWebhook(ctx, hookID)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
h, err := webhook_service.ToHook(setting.AppURL+"/-/admin", updated) h, err := webhook_service.ToHook(setting.AppURL+"/-/admin", updated)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
ctx.JSON(http.StatusOK, h) ctx.JSON(http.StatusOK, h)
@ -343,7 +343,7 @@ func editHook(ctx *context.APIContext, form *api.EditHookOption, w *webhook.Webh
Color: form.Config["color"], Color: form.Config["color"],
}) })
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return false return false
} }
w.Meta = string(meta) w.Meta = string(meta)
@ -369,7 +369,7 @@ func editHook(ctx *context.APIContext, form *api.EditHookOption, w *webhook.Webh
err := w.SetHeaderAuthorization(form.AuthorizationHeader) err := w.SetHeaderAuthorization(form.AuthorizationHeader)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return false return false
} }
@ -391,7 +391,7 @@ func editHook(ctx *context.APIContext, form *api.EditHookOption, w *webhook.Webh
w.HookEvents[webhook_module.HookEventPullRequestSync] = pullHook(form.Events, string(webhook_module.HookEventPullRequestSync)) w.HookEvents[webhook_module.HookEventPullRequestSync] = pullHook(form.Events, string(webhook_module.HookEventPullRequestSync))
if err := w.UpdateEvent(); err != nil { if err := w.UpdateEvent(); err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return false return false
} }
@ -400,7 +400,7 @@ func editHook(ctx *context.APIContext, form *api.EditHookOption, w *webhook.Webh
} }
if err := webhook.UpdateWebhook(ctx, w); err != nil { if err := webhook.UpdateWebhook(ctx, w); err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return false return false
} }
return true return true
@ -412,7 +412,7 @@ func DeleteOwnerHook(ctx *context.APIContext, owner *user_model.User, hookID int
if webhook.IsErrWebhookNotExist(err) { if webhook.IsErrWebhookNotExist(err) {
ctx.APIErrorNotFound() ctx.APIErrorNotFound()
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
return return
} }

View File

@ -104,7 +104,7 @@ func EnableOrDisableWorkflow(ctx *context.APIContext, workflowID string, isEnabl
func ListActionWorkflows(ctx *context.APIContext) ([]*api.ActionWorkflow, error) { func ListActionWorkflows(ctx *context.APIContext) ([]*api.ActionWorkflow, error) {
defaultBranchCommit, err := ctx.Repo.GitRepo.GetBranchCommit(ctx.Repo.Repository.DefaultBranch) defaultBranchCommit, err := ctx.Repo.GitRepo.GetBranchCommit(ctx.Repo.Repository.DefaultBranch)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err.Error()) ctx.APIErrorInternal(err)
return nil, err return nil, err
} }

View File

@ -5,6 +5,7 @@
package context package context
import ( import (
"errors"
"fmt" "fmt"
"net/http" "net/http"
"net/url" "net/url"
@ -17,6 +18,7 @@ import (
"code.gitea.io/gitea/modules/httpcache" "code.gitea.io/gitea/modules/httpcache"
"code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/util"
"code.gitea.io/gitea/modules/web" "code.gitea.io/gitea/modules/web"
web_types "code.gitea.io/gitea/modules/web/types" web_types "code.gitea.io/gitea/modules/web/types"
) )
@ -108,7 +110,11 @@ type APIRepoArchivedError struct {
// APIErrorInternal responds with error message, status is 500 // APIErrorInternal responds with error message, status is 500
func (ctx *APIContext) APIErrorInternal(err error) { func (ctx *APIContext) APIErrorInternal(err error) {
log.ErrorWithSkip(1, "InternalServerError: %v", err) ctx.apiErrorInternal(1, err)
}
func (ctx *APIContext) apiErrorInternal(skip int, err error) {
log.ErrorWithSkip(skip+1, "InternalServerError: %v", err)
var message string var message string
if !setting.IsProd || (ctx.Doer != nil && ctx.Doer.IsAdmin) { if !setting.IsProd || (ctx.Doer != nil && ctx.Doer.IsAdmin) {
@ -273,7 +279,7 @@ func ReferencesGitRepo(allowEmpty ...bool) func(ctx *APIContext) {
var err error var err error
ctx.Repo.GitRepo, err = gitrepo.RepositoryFromRequestContextOrOpen(ctx, ctx.Repo.Repository) ctx.Repo.GitRepo, err = gitrepo.RepositoryFromRequestContextOrOpen(ctx, ctx.Repo.Repository)
if err != nil { if err != nil {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
return return
} }
} }
@ -344,12 +350,12 @@ func (ctx *APIContext) GetErrMsg() string {
// NotFoundOrServerError use error check function to determine if the error // NotFoundOrServerError use error check function to determine if the error
// is about not found. It responds with 404 status code for not found 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. // or error context description for logging purpose of 500 server error.
func (ctx *APIContext) NotFoundOrServerError(logMsg string, errCheck func(error) bool, logErr error) { func (ctx *APIContext) NotFoundOrServerError(err error) {
if errCheck(logErr) { if errors.Is(err, util.ErrNotExist) {
ctx.JSON(http.StatusNotFound, nil) ctx.JSON(http.StatusNotFound, nil)
return return
} }
ctx.APIError(http.StatusInternalServerError, logMsg) ctx.APIErrorInternal(err)
} }
// IsUserSiteAdmin returns true if current user is a site admin // IsUserSiteAdmin returns true if current user is a site admin

View File

@ -44,7 +44,7 @@ func UserIDAssignmentAPI() func(ctx *APIContext) {
if user_model.IsErrUserNotExist(err) { if user_model.IsErrUserNotExist(err) {
ctx.APIError(http.StatusNotFound, err) ctx.APIError(http.StatusNotFound, err)
} else { } else {
ctx.APIError(http.StatusInternalServerError, err) ctx.APIErrorInternal(err)
} }
} }
} }