mirror of
https://github.com/astaxie/beego.git
synced 2024-11-22 18:00:55 +00:00
refactor of error response and fix err code bug
This commit is contained in:
parent
443d71397c
commit
0859ec570c
@ -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.
|
// 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) {
|
func (c *Controller) CustomAbort(status int, body string) {
|
||||||
c.Ctx.Output.Status = status
|
|
||||||
// first panic from ErrorMaps, is is user defined error functions.
|
// first panic from ErrorMaps, is is user defined error functions.
|
||||||
if _, ok := ErrorMaps[body]; ok {
|
if _, ok := ErrorMaps[body]; ok {
|
||||||
|
c.Ctx.Output.Status = status
|
||||||
panic(body)
|
panic(body)
|
||||||
}
|
}
|
||||||
// last panic user string
|
// last panic user string
|
||||||
|
c.Ctx.ResponseWriter.WriteHeader(status)
|
||||||
c.Ctx.ResponseWriter.Write([]byte(body))
|
c.Ctx.ResponseWriter.Write([]byte(body))
|
||||||
panic(ErrAbort)
|
panic(ErrAbort)
|
||||||
}
|
}
|
||||||
|
3
error.go
3
error.go
@ -388,8 +388,11 @@ func exception(errCode string, ctx *context.Context) {
|
|||||||
if err == nil {
|
if err == nil {
|
||||||
return v
|
return v
|
||||||
}
|
}
|
||||||
|
if ctx.Output.Status == 0 {
|
||||||
return 503
|
return 503
|
||||||
}
|
}
|
||||||
|
return ctx.Output.Status
|
||||||
|
}
|
||||||
|
|
||||||
for _, ec := range []string{errCode, "503", "500"} {
|
for _, ec := range []string{errCode, "503", "500"} {
|
||||||
if h, ok := ErrorMaps[ec]; ok {
|
if h, ok := ErrorMaps[ec]; ok {
|
||||||
|
@ -844,7 +844,7 @@ func (p *ControllerRegister) recoverPanic(context *beecontext.Context) {
|
|||||||
}
|
}
|
||||||
if !BConfig.RecoverPanic {
|
if !BConfig.RecoverPanic {
|
||||||
panic(err)
|
panic(err)
|
||||||
} else {
|
}
|
||||||
if BConfig.EnableErrorsShow {
|
if BConfig.EnableErrorsShow {
|
||||||
if _, ok := ErrorMaps[fmt.Sprint(err)]; ok {
|
if _, ok := ErrorMaps[fmt.Sprint(err)]; ok {
|
||||||
exception(fmt.Sprint(err), context)
|
exception(fmt.Sprint(err), context)
|
||||||
@ -866,7 +866,6 @@ func (p *ControllerRegister) recoverPanic(context *beecontext.Context) {
|
|||||||
showErr(err, context, stack)
|
showErr(err, context, stack)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func toURL(params map[string]string) string {
|
func toURL(params map[string]string) string {
|
||||||
|
Loading…
Reference in New Issue
Block a user