diff options
author | zeripath <art27@cantab.net> | 2019-04-09 19:10:42 +0100 |
---|---|---|
committer | Lauris BH <lauris@nix.lv> | 2019-04-09 21:10:42 +0300 |
commit | 0af0b078f9f2f56615086de2fb50676266c59752 (patch) | |
tree | 31bc1847189e7b5fd60e291680935f0aaa91ff02 /modules/context | |
parent | 2b9b3310f62f6209cd83fcc082de1aca9a828f17 (diff) | |
download | gitea-0af0b078f9f2f56615086de2fb50676266c59752.tar.gz gitea-0af0b078f9f2f56615086de2fb50676266c59752.zip |
wrap the ServerError and NotFound and log from the caller (#6550)
Diffstat (limited to 'modules/context')
-rw-r--r-- | modules/context/context.go | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/modules/context/context.go b/modules/context/context.go index 07e2b7b61f..c7534a16cd 100644 --- a/modules/context/context.go +++ b/modules/context/context.go @@ -151,8 +151,12 @@ func (ctx *Context) RenderWithErr(msg string, tpl base.TplName, form interface{} // NotFound displays a 404 (Not Found) page and prints the given error, if any. func (ctx *Context) NotFound(title string, err error) { + ctx.notFoundInternal(title, err) +} + +func (ctx *Context) notFoundInternal(title string, err error) { if err != nil { - log.Error("%s: %v", title, err) + log.ErrorWithSkip(2, "%s: %v", title, err) if macaron.Env != macaron.PROD { ctx.Data["ErrorMsg"] = err } @@ -166,8 +170,12 @@ func (ctx *Context) NotFound(title string, err error) { // ServerError displays a 500 (Internal Server Error) page and prints the given // error, if any. func (ctx *Context) ServerError(title string, err error) { + ctx.serverErrorInternal(title, err) +} + +func (ctx *Context) serverErrorInternal(title string, err error) { if err != nil { - log.Error("%s: %v", title, err) + log.ErrorWithSkip(2, "%s: %v", title, err) if macaron.Env != macaron.PROD { ctx.Data["ErrorMsg"] = err } @@ -182,11 +190,11 @@ func (ctx *Context) ServerError(title string, err error) { // or error context description for logging purpose of 500 server error. func (ctx *Context) NotFoundOrServerError(title string, errck func(error) bool, err error) { if errck(err) { - ctx.NotFound(title, err) + ctx.notFoundInternal(title, err) return } - ctx.ServerError(title, err) + ctx.serverErrorInternal(title, err) } // HandleText handles HTTP status code |