6666package v1
6767
6868import (
69+ "errors"
6970 "fmt"
7071 "net/http"
7172 "strings"
@@ -118,7 +119,7 @@ func sudo() func(ctx *context.APIContext) {
118119 if user_model .IsErrUserNotExist (err ) {
119120 ctx .APIErrorNotFound ()
120121 } else {
121- ctx .APIError ( http . StatusInternalServerError , err )
122+ ctx .APIErrorInternal ( err )
122123 }
123124 return
124125 }
@@ -156,10 +157,10 @@ func repoAssignment() func(ctx *context.APIContext) {
156157 } else if user_model .IsErrUserRedirectNotExist (err ) {
157158 ctx .APIErrorNotFound ("GetUserByName" , err )
158159 } else {
159- ctx .APIError ( http . StatusInternalServerError , err )
160+ ctx .APIErrorInternal ( err )
160161 }
161162 } else {
162- ctx .APIError ( http . StatusInternalServerError , err )
163+ ctx .APIErrorInternal ( err )
163164 }
164165 return
165166 }
@@ -177,10 +178,10 @@ func repoAssignment() func(ctx *context.APIContext) {
177178 } else if repo_model .IsErrRedirectNotExist (err ) {
178179 ctx .APIErrorNotFound ()
179180 } else {
180- ctx .APIError ( http . StatusInternalServerError , err )
181+ ctx .APIErrorInternal ( err )
181182 }
182183 } else {
183- ctx .APIError ( http . StatusInternalServerError , err )
184+ ctx .APIErrorInternal ( err )
184185 }
185186 return
186187 }
@@ -192,7 +193,7 @@ func repoAssignment() func(ctx *context.APIContext) {
192193 taskID := ctx .Data ["ActionsTaskID" ].(int64 )
193194 task , err := actions_model .GetTaskByID (ctx , taskID )
194195 if err != nil {
195- ctx .APIError ( http . StatusInternalServerError , err )
196+ ctx .APIErrorInternal ( err )
196197 return
197198 }
198199 if task .RepoID != repo .ID {
@@ -207,14 +208,14 @@ func repoAssignment() func(ctx *context.APIContext) {
207208 }
208209
209210 if err := ctx .Repo .Repository .LoadUnits (ctx ); err != nil {
210- ctx .APIError ( http . StatusInternalServerError , err )
211+ ctx .APIErrorInternal ( err )
211212 return
212213 }
213214 ctx .Repo .Permission .SetUnitsWithDefaultAccessMode (ctx .Repo .Repository .Units , ctx .Repo .Permission .AccessMode )
214215 } else {
215216 ctx .Repo .Permission , err = access_model .GetUserRepoPermission (ctx , repo , ctx .Doer )
216217 if err != nil {
217- ctx .APIError ( http . StatusInternalServerError , err )
218+ ctx .APIErrorInternal ( err )
218219 return
219220 }
220221 }
@@ -474,13 +475,14 @@ func reqOrgOwnership() func(ctx *context.APIContext) {
474475 } else if ctx .Org .Team != nil {
475476 orgID = ctx .Org .Team .OrgID
476477 } else {
477- ctx .APIError (http .StatusInternalServerError , "reqOrgOwnership: unprepared context" )
478+ setting .PanicInDevOrTesting ("reqOrgOwnership: unprepared context" )
479+ ctx .APIErrorInternal (errors .New ("reqOrgOwnership: unprepared context" ))
478480 return
479481 }
480482
481483 isOwner , err := organization .IsOrganizationOwner (ctx , orgID , ctx .Doer .ID )
482484 if err != nil {
483- ctx .APIError ( http . StatusInternalServerError , err )
485+ ctx .APIErrorInternal ( err )
484486 return
485487 } else if ! isOwner {
486488 if ctx .Org .Organization != nil {
@@ -500,26 +502,27 @@ func reqTeamMembership() func(ctx *context.APIContext) {
500502 return
501503 }
502504 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" ))
504507 return
505508 }
506509
507510 orgID := ctx .Org .Team .OrgID
508511 isOwner , err := organization .IsOrganizationOwner (ctx , orgID , ctx .Doer .ID )
509512 if err != nil {
510- ctx .APIError ( http . StatusInternalServerError , err )
513+ ctx .APIErrorInternal ( err )
511514 return
512515 } else if isOwner {
513516 return
514517 }
515518
516519 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 )
518521 return
519522 } else if ! isTeamMember {
520523 isOrgMember , err := organization .IsOrganizationMember (ctx , orgID , ctx .Doer .ID )
521524 if err != nil {
522- ctx .APIError ( http . StatusInternalServerError , err )
525+ ctx .APIErrorInternal ( err )
523526 } else if isOrgMember {
524527 ctx .APIError (http .StatusForbidden , "Must be a team member" )
525528 } else {
@@ -543,12 +546,13 @@ func reqOrgMembership() func(ctx *context.APIContext) {
543546 } else if ctx .Org .Team != nil {
544547 orgID = ctx .Org .Team .OrgID
545548 } else {
546- ctx .APIError (http .StatusInternalServerError , "reqOrgMembership: unprepared context" )
549+ setting .PanicInDevOrTesting ("reqOrgMembership: unprepared context" )
550+ ctx .APIErrorInternal (errors .New ("reqOrgMembership: unprepared context" ))
547551 return
548552 }
549553
550554 if isMember , err := organization .IsOrganizationMember (ctx , orgID , ctx .Doer .ID ); err != nil {
551- ctx .APIError ( http . StatusInternalServerError , err )
555+ ctx .APIErrorInternal ( err )
552556 return
553557 } else if ! isMember {
554558 if ctx .Org .Organization != nil {
@@ -615,10 +619,10 @@ func orgAssignment(args ...bool) func(ctx *context.APIContext) {
615619 } else if user_model .IsErrUserRedirectNotExist (err ) {
616620 ctx .APIErrorNotFound ("GetOrgByName" , err )
617621 } else {
618- ctx .APIError ( http . StatusInternalServerError , err )
622+ ctx .APIErrorInternal ( err )
619623 }
620624 } else {
621- ctx .APIError ( http . StatusInternalServerError , err )
625+ ctx .APIErrorInternal ( err )
622626 }
623627 return
624628 }
@@ -631,7 +635,7 @@ func orgAssignment(args ...bool) func(ctx *context.APIContext) {
631635 if organization .IsErrTeamNotExist (err ) {
632636 ctx .APIErrorNotFound ()
633637 } else {
634- ctx .APIError ( http . StatusInternalServerError , err )
638+ ctx .APIErrorInternal ( err )
635639 }
636640 return
637641 }
0 commit comments