diff options
author | ᴜɴᴋɴᴡᴏɴ <u@gogs.io> | 2020-03-16 01:22:27 +0800 |
---|---|---|
committer | ᴜɴᴋɴᴡᴏɴ <u@gogs.io> | 2020-03-16 01:22:27 +0800 |
commit | 9e9ca66467116e9079a2639c00e9e623aca23015 (patch) | |
tree | dacdef5392608ff7107e4dd498959d4899e13e54 /internal/cmd/web.go | |
parent | 82ff0c5852f29daa5f95d965fd50665581e7ea3c (diff) |
refactor: unify error handling in routing layer
Diffstat (limited to 'internal/cmd/web.go')
-rw-r--r-- | internal/cmd/web.go | 6 |
1 files changed, 3 insertions, 3 deletions
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 } }) |