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:
@ -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
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user