1
0
mirror of https://github.com/astaxie/beego.git synced 2024-11-25 16:10:55 +00:00
This commit is contained in:
astaxie 2015-03-30 20:35:57 +08:00
parent 2c9363d29b
commit 26130a5df6
2 changed files with 12 additions and 20 deletions

View File

@ -439,24 +439,26 @@ func exception(errcode string, ctx *context.Context) {
if err != nil { if err != nil {
code = 503 code = 503
} }
ctx.ResponseWriter.WriteHeader(code)
if h, ok := ErrorMaps[errcode]; ok { if h, ok := ErrorMaps[errcode]; ok {
executeError(h, ctx) executeError(h, ctx, code)
return return
} else if h, ok := ErrorMaps["503"]; ok { } else if h, ok := ErrorMaps["503"]; ok {
executeError(h, ctx) executeError(h, ctx, code)
return return
} else { } else {
ctx.ResponseWriter.WriteHeader(code)
ctx.WriteString(errcode) ctx.WriteString(errcode)
} }
} }
func executeError(err *errorInfo, ctx *context.Context) { func executeError(err *errorInfo, ctx *context.Context, code int) {
if err.errorType == errorTypeHandler { if err.errorType == errorTypeHandler {
ctx.ResponseWriter.WriteHeader(code)
err.handler(ctx.ResponseWriter, ctx.Request) err.handler(ctx.ResponseWriter, ctx.Request)
return return
} }
if err.errorType == errorTypeController { if err.errorType == errorTypeController {
ctx.Output.SetStatus(code)
//Invoke the request handler //Invoke the request handler
vc := reflect.New(err.controllerType) vc := reflect.New(err.controllerType)
execController, ok := vc.Interface().(ControllerInterface) execController, ok := vc.Interface().(ControllerInterface)
@ -476,11 +478,9 @@ func executeError(err *errorInfo, ctx *context.Context) {
method.Call(in) method.Call(in)
//render template //render template
if ctx.Output.Status == 0 { if AutoRender {
if AutoRender { if err := execController.Render(); err != nil {
if err := execController.Render(); err != nil { panic(err)
panic(err)
}
} }
} }

View File

@ -862,8 +862,8 @@ func (p *ControllerRegistor) recoverPanic(context *beecontext.Context) {
panic(err) panic(err)
} else { } else {
if ErrorsShow { if ErrorsShow {
if handler, ok := ErrorMaps[fmt.Sprint(err)]; ok { if _, ok := ErrorMaps[fmt.Sprint(err)]; ok {
executeError(handler, context) exception(fmt.Sprint(err), context)
return return
} }
} }
@ -886,15 +886,7 @@ func (p *ControllerRegistor) recoverPanic(context *beecontext.Context) {
} else { } else {
// in production model show all infomation // in production model show all infomation
if ErrorsShow { if ErrorsShow {
if handler, ok := ErrorMaps[fmt.Sprint(err)]; ok { exception(fmt.Sprint(err), context)
executeError(handler, context)
return
} else if handler, ok := ErrorMaps["503"]; ok {
executeError(handler, context)
return
} else {
context.WriteString(fmt.Sprint(err))
}
} else { } else {
Critical("the request url is ", context.Input.Url()) Critical("the request url is ", context.Input.Url())
Critical("Handler crashed with error", err) Critical("Handler crashed with error", err)