Skip to content

Commit 96c6b2d

Browse files
fix: use APIErrorInternal for internal server errors
Replace all ctx.APIError(http.StatusInternalServerError, err) calls with ctx.APIErrorInternal(err) to match Gitea's standard error handling conventions.
1 parent 550704f commit 96c6b2d

File tree

2 files changed

+11
-13
lines changed

2 files changed

+11
-13
lines changed

routers/api/v1/org/org_actions_permissions.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ import (
77
"net/http"
88

99
actions_model "code.gitea.io/gitea/models/actions"
10-
"code.gitea.io/gitea/services/context"
1110
api "code.gitea.io/gitea/modules/structs"
1211
"code.gitea.io/gitea/modules/web"
12+
"code.gitea.io/gitea/services/context"
1313
)
1414

1515
// GetActionsPermissions returns the Actions token permissions for an organization
@@ -36,7 +36,7 @@ func GetActionsPermissions(ctx *context.APIContext) {
3636
// Only org owners should be able to modify these settings.
3737
isOwner, err := ctx.Org.Organization.IsOwnedBy(ctx, ctx.Doer.ID)
3838
if err != nil {
39-
ctx.APIError(http.StatusInternalServerError, err)
39+
ctx.APIErrorInternal(err)
4040
return
4141
} else if !isOwner {
4242
ctx.APIError(http.StatusForbidden, "You must be an organization owner")
@@ -45,7 +45,7 @@ func GetActionsPermissions(ctx *context.APIContext) {
4545

4646
perms, err := actions_model.GetOrgActionPermissions(ctx, ctx.Org.Organization.ID)
4747
if err != nil {
48-
ctx.APIError(http.StatusInternalServerError, err)
48+
ctx.APIErrorInternal(err)
4949
return
5050
}
5151

@@ -131,7 +131,7 @@ func UpdateActionsPermissions(ctx *context.APIContext) {
131131
}
132132

133133
if err := actions_model.CreateOrUpdateOrgPermissions(ctx, perm); err != nil {
134-
ctx.APIError(http.StatusInternalServerError, err)
134+
ctx.APIErrorInternal(err)
135135
return
136136
}
137137

@@ -177,7 +177,7 @@ func ListCrossRepoAccess(ctx *context.APIContext) {
177177

178178
rules, err := actions_model.ListCrossRepoAccessRules(ctx, ctx.Org.Organization.ID)
179179
if err != nil {
180-
ctx.APIError(http.StatusInternalServerError, err)
180+
ctx.APIErrorInternal(err)
181181
return
182182
}
183183

@@ -245,7 +245,7 @@ func AddCrossRepoAccess(ctx *context.APIContext) {
245245
}
246246

247247
if err := actions_model.CreateCrossRepoAccess(ctx, rule); err != nil {
248-
ctx.APIError(http.StatusInternalServerError, err)
248+
ctx.APIErrorInternal(err)
249249
return
250250
}
251251

@@ -300,7 +300,7 @@ func DeleteCrossRepoAccess(ctx *context.APIContext) {
300300
}
301301

302302
if err := actions_model.DeleteCrossRepoAccess(ctx, ruleID); err != nil {
303-
ctx.APIError(http.StatusInternalServerError, err)
303+
ctx.APIErrorInternal(err)
304304
return
305305
}
306306

@@ -336,4 +336,3 @@ func convertToCrossRepoAccessRule(rule *actions_model.ActionCrossRepoAccess) *ap
336336
AccessLevel: rule.AccessLevel,
337337
}
338338
}
339-

routers/api/v1/repo/repo_actions_permissions.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ import (
77
"net/http"
88

99
actions_model "code.gitea.io/gitea/models/actions"
10-
"code.gitea.io/gitea/services/context"
1110
api "code.gitea.io/gitea/modules/structs"
1211
"code.gitea.io/gitea/modules/web"
12+
"code.gitea.io/gitea/services/context"
1313
)
1414

1515
// GetActionsPermissions returns the Actions token permissions for a repository
@@ -47,7 +47,7 @@ func GetActionsPermissions(ctx *context.APIContext) {
4747

4848
perms, err := actions_model.GetRepoActionPermissions(ctx, ctx.Repo.Repository.ID)
4949
if err != nil {
50-
ctx.APIError(http.StatusInternalServerError, err)
50+
ctx.APIErrorInternal(err)
5151
return
5252
}
5353

@@ -135,7 +135,7 @@ func UpdateActionsPermissions(ctx *context.APIContext) {
135135
}
136136

137137
if err := actions_model.CreateOrUpdateRepoPermissions(ctx, perm); err != nil {
138-
ctx.APIError(http.StatusInternalServerError, err)
138+
ctx.APIErrorInternal(err)
139139
return
140140
}
141141

@@ -181,7 +181,7 @@ func ResetActionsPermissions(ctx *context.APIContext) {
181181
}
182182

183183
if err := actions_model.CreateOrUpdateRepoPermissions(ctx, defaultPerm); err != nil {
184-
ctx.APIError(http.StatusInternalServerError, err)
184+
ctx.APIErrorInternal(err)
185185
return
186186
}
187187

@@ -206,4 +206,3 @@ func convertToAPIPermissions(perm *actions_model.ActionTokenPermission) *api.Act
206206
MetadataRead: perm.MetadataRead,
207207
}
208208
}
209-

0 commit comments

Comments
 (0)