From 9e9ca66467116e9079a2639c00e9e623aca23015 Mon Sep 17 00:00:00 2001 From: ᴜɴᴋɴᴡᴏɴ Date: Mon, 16 Mar 2020 01:22:27 +0800 Subject: refactor: unify error handling in routing layer --- internal/cmd/web.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'internal/cmd/web.go') 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 } }) -- cgit v1.2.3