mirror of
https://github.com/astaxie/beego.git
synced 2024-11-22 05:40:54 +00:00
fix #1073
This commit is contained in:
parent
2c9363d29b
commit
26130a5df6
18
error.go
18
error.go
@ -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,11 +478,9 @@ 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)
|
||||
}
|
||||
if AutoRender {
|
||||
if err := execController.Render(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
|
14
router.go
14
router.go
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user