@@ -7,7 +7,6 @@ package repo
77
88import (
99 "encoding/base64"
10- "net/http"
1110
1211 "code.gitea.io/gitea/models"
1312 "code.gitea.io/gitea/modules/context"
@@ -53,12 +52,12 @@ func GetRawFile(ctx *context.APIContext) {
5352 if git .IsErrNotExist (err ) {
5453 ctx .NotFound ()
5554 } else {
56- ctx .Error (http . StatusInternalServerError , "GetBlobByPath" , err )
55+ ctx .Error (500 , "GetBlobByPath" , err )
5756 }
5857 return
5958 }
6059 if err = repo .ServeBlob (ctx .Context , blob ); err != nil {
61- ctx .Error (http . StatusInternalServerError , "ServeBlob" , err )
60+ ctx .Error (500 , "ServeBlob" , err )
6261 }
6362}
6463
@@ -91,7 +90,7 @@ func GetArchive(ctx *context.APIContext) {
9190 repoPath := models .RepoPath (ctx .Params (":username" ), ctx .Params (":reponame" ))
9291 gitRepo , err := git .OpenRepository (repoPath )
9392 if err != nil {
94- ctx .Error (http . StatusInternalServerError , "OpenRepository" , err )
93+ ctx .Error (500 , "OpenRepository" , err )
9594 return
9695 }
9796 ctx .Repo .GitRepo = gitRepo
@@ -131,7 +130,7 @@ func GetEditorconfig(ctx *context.APIContext) {
131130 if git .IsErrNotExist (err ) {
132131 ctx .NotFound (err )
133132 } else {
134- ctx .Error (http . StatusInternalServerError , "GetEditorconfig" , err )
133+ ctx .Error (500 , "GetEditorconfig" , err )
135134 }
136135 return
137136 }
@@ -142,7 +141,7 @@ func GetEditorconfig(ctx *context.APIContext) {
142141 ctx .NotFound (err )
143142 return
144143 }
145- ctx .JSON (http . StatusOK , def )
144+ ctx .JSON (200 , def )
146145}
147146
148147// CanWriteFiles returns true if repository is editable and user has proper access level.
@@ -211,9 +210,9 @@ func CreateFile(ctx *context.APIContext, apiOpts api.CreateFileOptions) {
211210 }
212211
213212 if fileResponse , err := createOrUpdateFile (ctx , opts ); err != nil {
214- ctx .Error (http . StatusInternalServerError , "CreateFile" , err )
213+ ctx .Error (500 , "CreateFile" , err )
215214 } else {
216- ctx .JSON (http . StatusCreated , fileResponse )
215+ ctx .JSON (201 , fileResponse )
217216 }
218217}
219218
@@ -275,9 +274,9 @@ func UpdateFile(ctx *context.APIContext, apiOpts api.UpdateFileOptions) {
275274 }
276275
277276 if fileResponse , err := createOrUpdateFile (ctx , opts ); err != nil {
278- ctx .Error (http . StatusInternalServerError , "UpdateFile" , err )
277+ ctx .Error (500 , "UpdateFile" , err )
279278 } else {
280- ctx .JSON (http . StatusOK , fileResponse )
279+ ctx .JSON (200 , fileResponse )
281280 }
282281}
283282
@@ -333,7 +332,7 @@ func DeleteFile(ctx *context.APIContext, apiOpts api.DeleteFileOptions) {
333332 // "200":
334333 // "$ref": "#/responses/FileDeleteResponse"
335334 if ! CanWriteFiles (ctx .Repo ) {
336- ctx .Error (http . StatusInternalServerError , "DeleteFile" , models.ErrUserDoesNotHaveAccessToRepo {
335+ ctx .Error (500 , "DeleteFile" , models.ErrUserDoesNotHaveAccessToRepo {
337336 UserID : ctx .User .ID ,
338337 RepoName : ctx .Repo .Repository .LowerName ,
339338 })
@@ -361,9 +360,9 @@ func DeleteFile(ctx *context.APIContext, apiOpts api.DeleteFileOptions) {
361360 }
362361
363362 if fileResponse , err := repofiles .DeleteRepoFile (ctx .Repo .Repository , ctx .User , opts ); err != nil {
364- ctx .Error (http . StatusInternalServerError , "DeleteFile" , err )
363+ ctx .Error (500 , "DeleteFile" , err )
365364 } else {
366- ctx .JSON (http . StatusOK , fileResponse )
365+ ctx .JSON (200 , fileResponse )
367366 }
368367}
369368
@@ -400,7 +399,7 @@ func GetContents(ctx *context.APIContext) {
400399 // "$ref": "#/responses/ContentsResponse"
401400
402401 if ! CanReadFiles (ctx .Repo ) {
403- ctx .Error (http . StatusInternalServerError , "GetContentsOrList" , models.ErrUserDoesNotHaveAccessToRepo {
402+ ctx .Error (500 , "GetContentsOrList" , models.ErrUserDoesNotHaveAccessToRepo {
404403 UserID : ctx .User .ID ,
405404 RepoName : ctx .Repo .Repository .LowerName ,
406405 })
@@ -411,9 +410,9 @@ func GetContents(ctx *context.APIContext) {
411410 ref := ctx .QueryTrim ("ref" )
412411
413412 if fileList , err := repofiles .GetContentsOrList (ctx .Repo .Repository , treePath , ref ); err != nil {
414- ctx .Error (http . StatusInternalServerError , "GetContentsOrList" , err )
413+ ctx .Error (500 , "GetContentsOrList" , err )
415414 } else {
416- ctx .JSON (http . StatusOK , fileList )
415+ ctx .JSON (200 , fileList )
417416 }
418417}
419418
0 commit comments