From cc5abc6b306ec035316c266a6484fb7725cbec32 Mon Sep 17 00:00:00 2001 From: JessonChan Date: Fri, 18 Sep 2015 17:03:00 +0800 Subject: [PATCH] default atoi func to handle exception --- error.go | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/error.go b/error.go index 1e047234..435c5d77 100644 --- a/error.go +++ b/error.go @@ -391,19 +391,22 @@ func ErrorController(c ControllerInterface) *App { // show error string as simple text message. // if error string is empty, show 503 or 500 error as default. func exception(errCode string, ctx *context.Context) { - for _, ec := range []string{errCode, "503", "500"} { - code, _ := strconv.Atoi(ec) - if code == 0 { - code = 503 + atoi := func(code string) int { + v, err := strconv.Atoi(code) + if err == nil { + return v } + return 503 + } + + for _, ec := range []string{errCode, "503", "500"} { if h, ok := ErrorMaps[ec]; ok { - executeError(h, ctx, code) + executeError(h, ctx, atoi(ec)) return } } //if 50x error has been removed from errorMap - //set 503 as default - ctx.ResponseWriter.WriteHeader(503) + ctx.ResponseWriter.WriteHeader(atoi(errCode)) ctx.WriteString(errCode) }