mirror of
https://github.com/astaxie/beego.git
synced 2024-11-22 17:50:58 +00:00
write error to response
This commit is contained in:
parent
c8bbfb75f0
commit
443d71397c
138
error.go
138
error.go
@ -210,159 +210,139 @@ var ErrorMaps = make(map[string]*errorInfo, 10)
|
|||||||
|
|
||||||
// show 401 unauthorized error.
|
// show 401 unauthorized error.
|
||||||
func unauthorized(rw http.ResponseWriter, r *http.Request) {
|
func unauthorized(rw http.ResponseWriter, r *http.Request) {
|
||||||
t, _ := template.New("beegoerrortemp").Parse(errtpl)
|
responseError(rw, r,
|
||||||
data := map[string]interface{}{
|
401,
|
||||||
"Title": http.StatusText(401),
|
"<br>The page you have requested can't be authorized."+
|
||||||
"BeegoVersion": VERSION,
|
|
||||||
}
|
|
||||||
data["Content"] = template.HTML("<br>The page you have requested can't be authorized." +
|
|
||||||
"<br>Perhaps you are here because:"+
|
"<br>Perhaps you are here because:"+
|
||||||
"<br><br><ul>"+
|
"<br><br><ul>"+
|
||||||
"<br>The credentials you supplied are incorrect"+
|
"<br>The credentials you supplied are incorrect"+
|
||||||
"<br>There are errors in the website address"+
|
"<br>There are errors in the website address"+
|
||||||
"</ul>")
|
"</ul>",
|
||||||
t.Execute(rw, data)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// show 402 Payment Required
|
// show 402 Payment Required
|
||||||
func paymentRequired(rw http.ResponseWriter, r *http.Request) {
|
func paymentRequired(rw http.ResponseWriter, r *http.Request) {
|
||||||
t, _ := template.New("beegoerrortemp").Parse(errtpl)
|
responseError(rw, r,
|
||||||
data := map[string]interface{}{
|
402,
|
||||||
"Title": http.StatusText(402),
|
"<br>The page you have requested Payment Required."+
|
||||||
"BeegoVersion": VERSION,
|
|
||||||
}
|
|
||||||
data["Content"] = template.HTML("<br>The page you have requested Payment Required." +
|
|
||||||
"<br>Perhaps you are here because:"+
|
"<br>Perhaps you are here because:"+
|
||||||
"<br><br><ul>"+
|
"<br><br><ul>"+
|
||||||
"<br>The credentials you supplied are incorrect"+
|
"<br>The credentials you supplied are incorrect"+
|
||||||
"<br>There are errors in the website address"+
|
"<br>There are errors in the website address"+
|
||||||
"</ul>")
|
"</ul>",
|
||||||
t.Execute(rw, data)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// show 403 forbidden error.
|
// show 403 forbidden error.
|
||||||
func forbidden(rw http.ResponseWriter, r *http.Request) {
|
func forbidden(rw http.ResponseWriter, r *http.Request) {
|
||||||
t, _ := template.New("beegoerrortemp").Parse(errtpl)
|
responseError(rw, r,
|
||||||
data := map[string]interface{}{
|
403,
|
||||||
"Title": http.StatusText(403),
|
"<br>The page you have requested is forbidden."+
|
||||||
"BeegoVersion": VERSION,
|
|
||||||
}
|
|
||||||
data["Content"] = template.HTML("<br>The page you have requested is forbidden." +
|
|
||||||
"<br>Perhaps you are here because:"+
|
"<br>Perhaps you are here because:"+
|
||||||
"<br><br><ul>"+
|
"<br><br><ul>"+
|
||||||
"<br>Your address may be blocked"+
|
"<br>Your address may be blocked"+
|
||||||
"<br>The site may be disabled"+
|
"<br>The site may be disabled"+
|
||||||
"<br>You need to log in"+
|
"<br>You need to log in"+
|
||||||
"</ul>")
|
"</ul>",
|
||||||
t.Execute(rw, data)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// show 404 not found error.
|
// show 404 not found error.
|
||||||
func notFound(rw http.ResponseWriter, r *http.Request) {
|
func notFound(rw http.ResponseWriter, r *http.Request) {
|
||||||
t, _ := template.New("beegoerrortemp").Parse(errtpl)
|
responseError(rw, r,
|
||||||
data := map[string]interface{}{
|
404,
|
||||||
"Title": http.StatusText(404),
|
"<br>The page you have requested has flown the coop."+
|
||||||
"BeegoVersion": VERSION,
|
|
||||||
}
|
|
||||||
data["Content"] = template.HTML("<br>The page you have requested has flown the coop." +
|
|
||||||
"<br>Perhaps you are here because:"+
|
"<br>Perhaps you are here because:"+
|
||||||
"<br><br><ul>"+
|
"<br><br><ul>"+
|
||||||
"<br>The page has moved"+
|
"<br>The page has moved"+
|
||||||
"<br>The page no longer exists"+
|
"<br>The page no longer exists"+
|
||||||
"<br>You were looking for your puppy and got lost"+
|
"<br>You were looking for your puppy and got lost"+
|
||||||
"<br>You like 404 pages"+
|
"<br>You like 404 pages"+
|
||||||
"</ul>")
|
"</ul>",
|
||||||
t.Execute(rw, data)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// show 405 Method Not Allowed
|
// show 405 Method Not Allowed
|
||||||
func methodNotAllowed(rw http.ResponseWriter, r *http.Request) {
|
func methodNotAllowed(rw http.ResponseWriter, r *http.Request) {
|
||||||
t, _ := template.New("beegoerrortemp").Parse(errtpl)
|
responseError(rw, r,
|
||||||
data := map[string]interface{}{
|
405,
|
||||||
"Title": http.StatusText(405),
|
"<br>The method you have requested Not Allowed."+
|
||||||
"BeegoVersion": VERSION,
|
|
||||||
}
|
|
||||||
data["Content"] = template.HTML("<br>The method you have requested Not Allowed." +
|
|
||||||
"<br>Perhaps you are here because:"+
|
"<br>Perhaps you are here because:"+
|
||||||
"<br><br><ul>"+
|
"<br><br><ul>"+
|
||||||
"<br>The method specified in the Request-Line is not allowed for the resource identified by the Request-URI"+
|
"<br>The method specified in the Request-Line is not allowed for the resource identified by the Request-URI"+
|
||||||
"<br>The response MUST include an Allow header containing a list of valid methods for the requested resource."+
|
"<br>The response MUST include an Allow header containing a list of valid methods for the requested resource."+
|
||||||
"</ul>")
|
"</ul>",
|
||||||
t.Execute(rw, data)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// show 500 internal server error.
|
// show 500 internal server error.
|
||||||
func internalServerError(rw http.ResponseWriter, r *http.Request) {
|
func internalServerError(rw http.ResponseWriter, r *http.Request) {
|
||||||
t, _ := template.New("beegoerrortemp").Parse(errtpl)
|
responseError(rw, r,
|
||||||
data := map[string]interface{}{
|
500,
|
||||||
"Title": http.StatusText(500),
|
"<br>The page you have requested is down right now."+
|
||||||
"BeegoVersion": VERSION,
|
|
||||||
}
|
|
||||||
data["Content"] = template.HTML("<br>The page you have requested is down right now." +
|
|
||||||
"<br><br><ul>"+
|
"<br><br><ul>"+
|
||||||
"<br>Please try again later and report the error to the website administrator"+
|
"<br>Please try again later and report the error to the website administrator"+
|
||||||
"<br></ul>")
|
"<br></ul>",
|
||||||
t.Execute(rw, data)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// show 501 Not Implemented.
|
// show 501 Not Implemented.
|
||||||
func notImplemented(rw http.ResponseWriter, r *http.Request) {
|
func notImplemented(rw http.ResponseWriter, r *http.Request) {
|
||||||
t, _ := template.New("beegoerrortemp").Parse(errtpl)
|
responseError(rw, r,
|
||||||
data := map[string]interface{}{
|
501,
|
||||||
"Title": http.StatusText(504),
|
"<br>The page you have requested is Not Implemented."+
|
||||||
"BeegoVersion": VERSION,
|
|
||||||
}
|
|
||||||
data["Content"] = template.HTML("<br>The page you have requested is Not Implemented." +
|
|
||||||
"<br><br><ul>"+
|
"<br><br><ul>"+
|
||||||
"<br>Please try again later and report the error to the website administrator"+
|
"<br>Please try again later and report the error to the website administrator"+
|
||||||
"<br></ul>")
|
"<br></ul>",
|
||||||
t.Execute(rw, data)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// show 502 Bad Gateway.
|
// show 502 Bad Gateway.
|
||||||
func badGateway(rw http.ResponseWriter, r *http.Request) {
|
func badGateway(rw http.ResponseWriter, r *http.Request) {
|
||||||
t, _ := template.New("beegoerrortemp").Parse(errtpl)
|
responseError(rw, r,
|
||||||
data := map[string]interface{}{
|
502,
|
||||||
"Title": http.StatusText(502),
|
"<br>The page you have requested is down right now."+
|
||||||
"BeegoVersion": VERSION,
|
|
||||||
}
|
|
||||||
data["Content"] = template.HTML("<br>The page you have requested is down right now." +
|
|
||||||
"<br><br><ul>"+
|
"<br><br><ul>"+
|
||||||
"<br>The server, while acting as a gateway or proxy, received an invalid response from the upstream server it accessed in attempting to fulfill the request."+
|
"<br>The server, while acting as a gateway or proxy, received an invalid response from the upstream server it accessed in attempting to fulfill the request."+
|
||||||
"<br>Please try again later and report the error to the website administrator"+
|
"<br>Please try again later and report the error to the website administrator"+
|
||||||
"<br></ul>")
|
"<br></ul>",
|
||||||
t.Execute(rw, data)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// show 503 service unavailable error.
|
// show 503 service unavailable error.
|
||||||
func serviceUnavailable(rw http.ResponseWriter, r *http.Request) {
|
func serviceUnavailable(rw http.ResponseWriter, r *http.Request) {
|
||||||
t, _ := template.New("beegoerrortemp").Parse(errtpl)
|
responseError(rw, r,
|
||||||
data := map[string]interface{}{
|
503,
|
||||||
"Title": http.StatusText(503),
|
"<br>The page you have requested is unavailable."+
|
||||||
"BeegoVersion": VERSION,
|
|
||||||
}
|
|
||||||
data["Content"] = template.HTML("<br>The page you have requested is unavailable." +
|
|
||||||
"<br>Perhaps you are here because:"+
|
"<br>Perhaps you are here because:"+
|
||||||
"<br><br><ul>"+
|
"<br><br><ul>"+
|
||||||
"<br><br>The page is overloaded"+
|
"<br><br>The page is overloaded"+
|
||||||
"<br>Please try again later."+
|
"<br>Please try again later."+
|
||||||
"</ul>")
|
"</ul>",
|
||||||
t.Execute(rw, data)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// show 504 Gateway Timeout.
|
// show 504 Gateway Timeout.
|
||||||
func gatewayTimeout(rw http.ResponseWriter, r *http.Request) {
|
func gatewayTimeout(rw http.ResponseWriter, r *http.Request) {
|
||||||
t, _ := template.New("beegoerrortemp").Parse(errtpl)
|
responseError(rw, r,
|
||||||
data := map[string]interface{}{
|
504,
|
||||||
"Title": http.StatusText(504),
|
"<br>The page you have requested is unavailable"+
|
||||||
"BeegoVersion": VERSION,
|
|
||||||
}
|
|
||||||
data["Content"] = template.HTML("<br>The page you have requested is unavailable." +
|
|
||||||
"<br>Perhaps you are here because:"+
|
"<br>Perhaps you are here because:"+
|
||||||
"<br><br><ul>"+
|
"<br><br><ul>"+
|
||||||
"<br><br>The server, while acting as a gateway or proxy, did not receive a timely response from the upstream server specified by the URI."+
|
"<br><br>The server, while acting as a gateway or proxy, did not receive a timely response from the upstream server specified by the URI."+
|
||||||
"<br>Please try again later."+
|
"<br>Please try again later."+
|
||||||
"</ul>")
|
"</ul>",
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
func responseError(rw http.ResponseWriter, r *http.Request, errCode int, errContent string) {
|
||||||
|
t, _ := template.New("beegoerrortemp").Parse(errtpl)
|
||||||
|
data := map[string]interface{}{
|
||||||
|
"Title": http.StatusText(errCode),
|
||||||
|
"BeegoVersion": VERSION,
|
||||||
|
"Content": errContent,
|
||||||
|
}
|
||||||
t.Execute(rw, data)
|
t.Execute(rw, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user