aboutsummaryrefslogtreecommitdiff
path: root/internal/cmd
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/cmd
parent82ff0c5852f29daa5f95d965fd50665581e7ea3c (diff)
refactor: unify error handling in routing layer
Diffstat (limited to 'internal/cmd')
-rw-r--r--internal/cmd/hook.go3
-rw-r--r--internal/cmd/serv.go5
-rw-r--r--internal/cmd/web.go6
3 files changed, 6 insertions, 8 deletions
diff --git a/internal/cmd/hook.go b/internal/cmd/hook.go
index de95a57d..0e9136b0 100644
--- a/internal/cmd/hook.go
+++ b/internal/cmd/hook.go
@@ -23,7 +23,6 @@ import (
"gogs.io/gogs/internal/conf"
"gogs.io/gogs/internal/db"
- "gogs.io/gogs/internal/db/errors"
"gogs.io/gogs/internal/email"
"gogs.io/gogs/internal/httplib"
)
@@ -93,7 +92,7 @@ func runHookPreReceive(c *cli.Context) error {
repoID := com.StrTo(os.Getenv(db.ENV_REPO_ID)).MustInt64()
protectBranch, err := db.GetProtectBranchOfRepoByName(repoID, branchName)
if err != nil {
- if errors.IsErrBranchNotExist(err) {
+ if db.IsErrBranchNotExist(err) {
continue
}
fail("Internal error", "GetProtectBranchOfRepoByName [repo_id: %d, branch: %s]: %v", repoID, branchName, err)
diff --git a/internal/cmd/serv.go b/internal/cmd/serv.go
index 64e0f1d0..8c6349e3 100644
--- a/internal/cmd/serv.go
+++ b/internal/cmd/serv.go
@@ -18,7 +18,6 @@ import (
"gogs.io/gogs/internal/conf"
"gogs.io/gogs/internal/db"
- "gogs.io/gogs/internal/db/errors"
)
const (
@@ -164,7 +163,7 @@ func runServ(c *cli.Context) error {
owner, err := db.GetUserByName(ownerName)
if err != nil {
- if errors.IsUserNotExist(err) {
+ if db.IsErrUserNotExist(err) {
fail("Repository owner does not exist", "Unregistered owner: %s", ownerName)
}
fail("Internal error", "Failed to get repository owner '%s': %v", ownerName, err)
@@ -172,7 +171,7 @@ func runServ(c *cli.Context) error {
repo, err := db.GetRepositoryByName(owner.ID, repoName)
if err != nil {
- if errors.IsRepoNotExist(err) {
+ if db.IsErrRepoNotExist(err) {
fail(_ACCESS_DENIED_MESSAGE, "Repository does not exist: %s/%s", owner.Name, repoName)
}
fail("Internal error", "Failed to get repository: %v", err)
diff --git a/internal/cmd/web.go b/internal/cmd/web.go
index 078678b4..1d78e4a6 100644
--- a/internal/cmd/web.go
+++ b/internal/cmd/web.go
@@ -318,7 +318,7 @@ func runWeb(c *cli.Context) error {
m.Get("/attachments/:uuid", func(c *context.Context) {
attach, err := db.GetAttachmentByUUID(c.Params(":uuid"))
if err != nil {
- c.NotFoundOrServerError("GetAttachmentByUUID", db.IsErrAttachmentNotExist, err)
+ c.NotFoundOrError(err, "get attachment by UUID")
return
} else if !com.IsFile(attach.LocalPath()) {
c.NotFound()
@@ -327,7 +327,7 @@ func runWeb(c *cli.Context) error {
fr, err := os.Open(attach.LocalPath())
if err != nil {
- c.ServerError("open attachment file", err)
+ c.Error(err, "open attachment file")
return
}
defer fr.Close()
@@ -336,7 +336,7 @@ func runWeb(c *cli.Context) error {
c.Header().Set("Content-Disposition", fmt.Sprintf(`inline; filename="%s"`, attach.Name))
if _, err = io.Copy(c.Resp, fr); err != nil {
- c.ServerError("copy from file to response", err)
+ c.Error(err, "copy from file to response")
return
}
})