66
66
package v1
67
67
68
68
import (
69
+ "errors"
69
70
"fmt"
70
71
"net/http"
71
72
"strings"
@@ -118,7 +119,7 @@ func sudo() func(ctx *context.APIContext) {
118
119
if user_model .IsErrUserNotExist (err ) {
119
120
ctx .APIErrorNotFound ()
120
121
} else {
121
- ctx .APIError ( http . StatusInternalServerError , err )
122
+ ctx .APIErrorInternal ( err )
122
123
}
123
124
return
124
125
}
@@ -156,10 +157,10 @@ func repoAssignment() func(ctx *context.APIContext) {
156
157
} else if user_model .IsErrUserRedirectNotExist (err ) {
157
158
ctx .APIErrorNotFound ("GetUserByName" , err )
158
159
} else {
159
- ctx .APIError ( http . StatusInternalServerError , err )
160
+ ctx .APIErrorInternal ( err )
160
161
}
161
162
} else {
162
- ctx .APIError ( http . StatusInternalServerError , err )
163
+ ctx .APIErrorInternal ( err )
163
164
}
164
165
return
165
166
}
@@ -177,10 +178,10 @@ func repoAssignment() func(ctx *context.APIContext) {
177
178
} else if repo_model .IsErrRedirectNotExist (err ) {
178
179
ctx .APIErrorNotFound ()
179
180
} else {
180
- ctx .APIError ( http . StatusInternalServerError , err )
181
+ ctx .APIErrorInternal ( err )
181
182
}
182
183
} else {
183
- ctx .APIError ( http . StatusInternalServerError , err )
184
+ ctx .APIErrorInternal ( err )
184
185
}
185
186
return
186
187
}
@@ -192,7 +193,7 @@ func repoAssignment() func(ctx *context.APIContext) {
192
193
taskID := ctx .Data ["ActionsTaskID" ].(int64 )
193
194
task , err := actions_model .GetTaskByID (ctx , taskID )
194
195
if err != nil {
195
- ctx .APIError ( http . StatusInternalServerError , err )
196
+ ctx .APIErrorInternal ( err )
196
197
return
197
198
}
198
199
if task .RepoID != repo .ID {
@@ -207,14 +208,14 @@ func repoAssignment() func(ctx *context.APIContext) {
207
208
}
208
209
209
210
if err := ctx .Repo .Repository .LoadUnits (ctx ); err != nil {
210
- ctx .APIError ( http . StatusInternalServerError , err )
211
+ ctx .APIErrorInternal ( err )
211
212
return
212
213
}
213
214
ctx .Repo .Permission .SetUnitsWithDefaultAccessMode (ctx .Repo .Repository .Units , ctx .Repo .Permission .AccessMode )
214
215
} else {
215
216
ctx .Repo .Permission , err = access_model .GetUserRepoPermission (ctx , repo , ctx .Doer )
216
217
if err != nil {
217
- ctx .APIError ( http . StatusInternalServerError , err )
218
+ ctx .APIErrorInternal ( err )
218
219
return
219
220
}
220
221
}
@@ -474,13 +475,14 @@ func reqOrgOwnership() func(ctx *context.APIContext) {
474
475
} else if ctx .Org .Team != nil {
475
476
orgID = ctx .Org .Team .OrgID
476
477
} else {
477
- ctx .APIError (http .StatusInternalServerError , "reqOrgOwnership: unprepared context" )
478
+ setting .PanicInDevOrTesting ("reqOrgOwnership: unprepared context" )
479
+ ctx .APIErrorInternal (errors .New ("reqOrgOwnership: unprepared context" ))
478
480
return
479
481
}
480
482
481
483
isOwner , err := organization .IsOrganizationOwner (ctx , orgID , ctx .Doer .ID )
482
484
if err != nil {
483
- ctx .APIError ( http . StatusInternalServerError , err )
485
+ ctx .APIErrorInternal ( err )
484
486
return
485
487
} else if ! isOwner {
486
488
if ctx .Org .Organization != nil {
@@ -500,26 +502,27 @@ func reqTeamMembership() func(ctx *context.APIContext) {
500
502
return
501
503
}
502
504
if ctx .Org .Team == nil {
503
- ctx .APIError (http .StatusInternalServerError , "reqTeamMembership: unprepared context" )
505
+ setting .PanicInDevOrTesting ("reqTeamMembership: unprepared context" )
506
+ ctx .APIErrorInternal (errors .New ("reqTeamMembership: unprepared context" ))
504
507
return
505
508
}
506
509
507
510
orgID := ctx .Org .Team .OrgID
508
511
isOwner , err := organization .IsOrganizationOwner (ctx , orgID , ctx .Doer .ID )
509
512
if err != nil {
510
- ctx .APIError ( http . StatusInternalServerError , err )
513
+ ctx .APIErrorInternal ( err )
511
514
return
512
515
} else if isOwner {
513
516
return
514
517
}
515
518
516
519
if isTeamMember , err := organization .IsTeamMember (ctx , orgID , ctx .Org .Team .ID , ctx .Doer .ID ); err != nil {
517
- ctx .APIError ( http . StatusInternalServerError , err )
520
+ ctx .APIErrorInternal ( err )
518
521
return
519
522
} else if ! isTeamMember {
520
523
isOrgMember , err := organization .IsOrganizationMember (ctx , orgID , ctx .Doer .ID )
521
524
if err != nil {
522
- ctx .APIError ( http . StatusInternalServerError , err )
525
+ ctx .APIErrorInternal ( err )
523
526
} else if isOrgMember {
524
527
ctx .APIError (http .StatusForbidden , "Must be a team member" )
525
528
} else {
@@ -543,12 +546,13 @@ func reqOrgMembership() func(ctx *context.APIContext) {
543
546
} else if ctx .Org .Team != nil {
544
547
orgID = ctx .Org .Team .OrgID
545
548
} else {
546
- ctx .APIError (http .StatusInternalServerError , "reqOrgMembership: unprepared context" )
549
+ setting .PanicInDevOrTesting ("reqOrgMembership: unprepared context" )
550
+ ctx .APIErrorInternal (errors .New ("reqOrgMembership: unprepared context" ))
547
551
return
548
552
}
549
553
550
554
if isMember , err := organization .IsOrganizationMember (ctx , orgID , ctx .Doer .ID ); err != nil {
551
- ctx .APIError ( http . StatusInternalServerError , err )
555
+ ctx .APIErrorInternal ( err )
552
556
return
553
557
} else if ! isMember {
554
558
if ctx .Org .Organization != nil {
@@ -615,10 +619,10 @@ func orgAssignment(args ...bool) func(ctx *context.APIContext) {
615
619
} else if user_model .IsErrUserRedirectNotExist (err ) {
616
620
ctx .APIErrorNotFound ("GetOrgByName" , err )
617
621
} else {
618
- ctx .APIError ( http . StatusInternalServerError , err )
622
+ ctx .APIErrorInternal ( err )
619
623
}
620
624
} else {
621
- ctx .APIError ( http . StatusInternalServerError , err )
625
+ ctx .APIErrorInternal ( err )
622
626
}
623
627
return
624
628
}
@@ -631,7 +635,7 @@ func orgAssignment(args ...bool) func(ctx *context.APIContext) {
631
635
if organization .IsErrTeamNotExist (err ) {
632
636
ctx .APIErrorNotFound ()
633
637
} else {
634
- ctx .APIError ( http . StatusInternalServerError , err )
638
+ ctx .APIErrorInternal ( err )
635
639
}
636
640
return
637
641
}
0 commit comments