From 899e7994595f5fc500de8cdf39e1b737f9f00982 Mon Sep 17 00:00:00 2001 From: Unknwon Date: Tue, 26 Jul 2016 02:48:17 +0800 Subject: #1601 support delete issue comment --- modules/context/context.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'modules/context/context.go') diff --git a/modules/context/context.go b/modules/context/context.go index 6ca7e574f6..971d075d0f 100644 --- a/modules/context/context.go +++ b/modules/context/context.go @@ -105,6 +105,19 @@ func (ctx *Context) Handle(status int, title string, err error) { ctx.HTML(status, base.TplName(fmt.Sprintf("status/%d", status))) } +// HandleError use error check function to determine if server should +// response as client input error or server internal error. +// It responses with given status code for client error, +// or error context description for logging purpose of server error. +func (ctx *Context) HandleError(title string, errck func(error) bool, err error, status int) { + if errck(err) { + ctx.Error(status, err.Error()) + return + } + + ctx.Handle(500, title, err) +} + func (ctx *Context) HandleText(status int, title string) { if (status/100 == 4) || (status/100 == 5) { log.Error(4, "%s", title) -- cgit v1.2.3