1
0
mirror of https://github.com/astaxie/beego.git synced 2025-07-11 16:51:01 +00:00

refactor of error response and fix err code bug

This commit is contained in:
JessonChan
2016-03-17 09:46:34 +08:00
parent 443d71397c
commit 0859ec570c
3 changed files with 24 additions and 21 deletions

View File

@ -261,12 +261,13 @@ func (c *Controller) Abort(code string) {
// CustomAbort stops controller handler and show the error data, it's similar Aborts, but support status code and body.
func (c *Controller) CustomAbort(status int, body string) {
c.Ctx.Output.Status = status
// first panic from ErrorMaps, is is user defined error functions.
if _, ok := ErrorMaps[body]; ok {
c.Ctx.Output.Status = status
panic(body)
}
// last panic user string
c.Ctx.ResponseWriter.WriteHeader(status)
c.Ctx.ResponseWriter.Write([]byte(body))
panic(ErrAbort)
}