1
0
mirror of https://github.com/astaxie/beego.git synced 2024-11-26 07:11:29 +00:00
This commit is contained in:
astaxie 2015-03-30 20:35:57 +08:00
parent a002f78443
commit eedaea2fea
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 {
code = 503
}
ctx.ResponseWriter.WriteHeader(code)
if h, ok := ErrorMaps[errcode]; ok {
executeError(h, ctx)
executeError(h, ctx, code)
return
} else if h, ok := ErrorMaps["503"]; ok {
executeError(h, ctx)
executeError(h, ctx, code)
return
} else {
ctx.ResponseWriter.WriteHeader(code)
ctx.WriteString(errcode)
}
}
func executeError(err *errorInfo, ctx *context.Context) {
func executeError(err *errorInfo, ctx *context.Context, code int) {
if err.errorType == errorTypeHandler {
ctx.ResponseWriter.WriteHeader(code)
err.handler(ctx.ResponseWriter, ctx.Request)
return
}
if err.errorType == errorTypeController {
ctx.Output.SetStatus(code)
//Invoke the request handler
vc := reflect.New(err.controllerType)
execController, ok := vc.Interface().(ControllerInterface)
@ -476,13 +478,11 @@ func executeError(err *errorInfo, ctx *context.Context) {
method.Call(in)
//render template
if ctx.Output.Status == 0 {
if AutoRender {
if err := execController.Render(); err != nil {
panic(err)
}
}
}
// finish all runrouter. release resource
execController.Finish()

View File

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