mirror of
https://github.com/astaxie/beego.git
synced 2025-07-26 18:15:31 +00:00
error support controller
This commit is contained in:
@@ -31,7 +31,7 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/astaxie/beego/middleware"
|
||||
"github.com/astaxie/beego"
|
||||
"github.com/astaxie/beego/utils"
|
||||
)
|
||||
|
||||
@@ -53,24 +53,16 @@ func (ctx *Context) Redirect(status int, localurl string) {
|
||||
}
|
||||
|
||||
// Abort stops this request.
|
||||
// if middleware.ErrorMaps exists, panic body.
|
||||
// if middleware.HTTPExceptionMaps exists, panic HTTPException struct with status and body string.
|
||||
// if beego.ErrorMaps exists, panic body.
|
||||
func (ctx *Context) Abort(status int, body string) {
|
||||
ctx.ResponseWriter.WriteHeader(status)
|
||||
// first panic from ErrorMaps, is is user defined error functions.
|
||||
if _, ok := middleware.ErrorMaps[body]; ok {
|
||||
if _, ok := beego.ErrorMaps[body]; ok {
|
||||
panic(body)
|
||||
}
|
||||
// second panic from HTTPExceptionMaps, it is system defined functions.
|
||||
if e, ok := middleware.HTTPExceptionMaps[status]; ok {
|
||||
if len(body) >= 1 {
|
||||
e.Description = body
|
||||
}
|
||||
panic(e)
|
||||
}
|
||||
// last panic user string
|
||||
ctx.ResponseWriter.Write([]byte(body))
|
||||
panic("User stop run")
|
||||
panic(beego.USERSTOPRUN)
|
||||
}
|
||||
|
||||
// Write string to response body.
|
||||
|
Reference in New Issue
Block a user