1
0
mirror of https://github.com/astaxie/beego.git synced 2024-11-26 03:11:30 +00:00

default exception handler

This commit is contained in:
JessonChan 2015-09-18 10:31:10 +08:00
parent 4823a0f114
commit ead635e62f

View File

@ -390,18 +390,19 @@ func ErrorController(c ControllerInterface) *App {
// show error string as simple text message. // show error string as simple text message.
// if error string is empty, show 503 or 500 error as default. // if error string is empty, show 503 or 500 error as default.
func exception(errCode string, ctx *context.Context) { func exception(errCode string, ctx *context.Context) {
code, _ := strconv.Atoi(errCode) for _, ec := range []string{errCode, "503", "500"} {
code, _ := strconv.Atoi(ec)
if code == 0 { if code == 0 {
code = 503 code = 503
} }
for _, ec := range []string{errCode, "503", "500"} {
if h, ok := ErrorMaps[ec]; ok { if h, ok := ErrorMaps[ec]; ok {
executeError(h, ctx, code) executeError(h, ctx, code)
return return
} }
} }
//if 50x error has been removed from errorMap //if 50x error has been removed from errorMap
ctx.ResponseWriter.WriteHeader(code) //set 503 as default
ctx.ResponseWriter.WriteHeader(503)
ctx.WriteString(errCode) ctx.WriteString(errCode)
} }