aboutsummaryrefslogtreecommitdiff
path: root/internal/route/api/v1/repo/branch.go
diff options
context:
space:
mode:
authorᴜɴᴋɴᴡᴏɴ <u@gogs.io>2020-03-16 01:22:27 +0800
committerᴜɴᴋɴᴡᴏɴ <u@gogs.io>2020-03-16 01:22:27 +0800
commit9e9ca66467116e9079a2639c00e9e623aca23015 (patch)
treedacdef5392608ff7107e4dd498959d4899e13e54 /internal/route/api/v1/repo/branch.go
parent82ff0c5852f29daa5f95d965fd50665581e7ea3c (diff)
refactor: unify error handling in routing layer
Diffstat (limited to 'internal/route/api/v1/repo/branch.go')
-rw-r--r--internal/route/api/v1/repo/branch.go21
1 files changed, 8 insertions, 13 deletions
diff --git a/internal/route/api/v1/repo/branch.go b/internal/route/api/v1/repo/branch.go
index b90d1e24..3ddf62cc 100644
--- a/internal/route/api/v1/repo/branch.go
+++ b/internal/route/api/v1/repo/branch.go
@@ -6,38 +6,33 @@ package repo
import (
api "github.com/gogs/go-gogs-client"
- convert2 "gogs.io/gogs/internal/route/api/v1/convert"
"gogs.io/gogs/internal/context"
- "gogs.io/gogs/internal/db/errors"
+ "gogs.io/gogs/internal/route/api/v1/convert"
)
// https://github.com/gogs/go-gogs-client/wiki/Repositories#get-branch
func GetBranch(c *context.APIContext) {
branch, err := c.Repo.Repository.GetBranch(c.Params("*"))
if err != nil {
- if errors.IsErrBranchNotExist(err) {
- c.Error(404, "GetBranch", err)
- } else {
- c.Error(500, "GetBranch", err)
- }
+ c.NotFoundOrError(err, "get branch")
return
}
commit, err := branch.GetCommit()
if err != nil {
- c.Error(500, "GetCommit", err)
+ c.Error(err, "get commit")
return
}
- c.JSON(200, convert2.ToBranch(branch, commit))
+ c.JSONSuccess( convert.ToBranch(branch, commit))
}
// https://github.com/gogs/go-gogs-client/wiki/Repositories#list-branches
func ListBranches(c *context.APIContext) {
branches, err := c.Repo.Repository.GetBranches()
if err != nil {
- c.Error(500, "GetBranches", err)
+ c.Error(err, "get branches")
return
}
@@ -45,11 +40,11 @@ func ListBranches(c *context.APIContext) {
for i := range branches {
commit, err := branches[i].GetCommit()
if err != nil {
- c.Error(500, "GetCommit", err)
+ c.Error(err, "get commit")
return
}
- apiBranches[i] = convert2.ToBranch(branches[i], commit)
+ apiBranches[i] = convert.ToBranch(branches[i], commit)
}
- c.JSON(200, &apiBranches)
+ c.JSONSuccess( &apiBranches)
}