1
0
mirror of https://github.com/astaxie/beego.git synced 2025-06-11 05:10:39 +00:00

update middleware & beego's error

This commit is contained in:
astaxie
2013-09-11 17:00:39 +08:00
parent 0da2059f79
commit 9f6b803a10
4 changed files with 33 additions and 299 deletions

View File

@ -5,6 +5,7 @@ import (
"html/template"
"net/http"
"runtime"
"strconv"
)
var (
@ -286,3 +287,22 @@ func RegisterErrorHander() {
ErrorMaps["500"] = InternalServerError
}
}
func Exception(errcode string, w http.ResponseWriter, r *http.Request, msg string) {
if h, ok := ErrorMaps[errcode]; ok {
h(w, r)
return
} else {
isint, err := strconv.Atoi(errcode)
if err != nil {
isint = 500
}
if isint == 400 {
msg = "404 page not found"
}
w.Header().Set("Content-Type", "text/plain; charset=utf-8")
w.WriteHeader(isint)
fmt.Fprintln(w, msg)
return
}
}