mirror of
https://github.com/astaxie/beego.git
synced 2024-11-25 18:50:55 +00:00
default atoi func to handle exception
This commit is contained in:
parent
2a96f33543
commit
cc5abc6b30
17
error.go
17
error.go
@ -391,19 +391,22 @@ 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) {
|
||||||
for _, ec := range []string{errCode, "503", "500"} {
|
atoi := func(code string) int {
|
||||||
code, _ := strconv.Atoi(ec)
|
v, err := strconv.Atoi(code)
|
||||||
if code == 0 {
|
if err == nil {
|
||||||
code = 503
|
return v
|
||||||
}
|
}
|
||||||
|
return 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, atoi(ec))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//if 50x error has been removed from errorMap
|
//if 50x error has been removed from errorMap
|
||||||
//set 503 as default
|
ctx.ResponseWriter.WriteHeader(atoi(errCode))
|
||||||
ctx.ResponseWriter.WriteHeader(503)
|
|
||||||
ctx.WriteString(errCode)
|
ctx.WriteString(errCode)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user