diff options
Diffstat (limited to 'modules/context')
-rw-r--r-- | modules/context/context.go | 13 |
1 files changed, 13 insertions, 0 deletions
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) |