Added 503 error page and streamlined error paging
This commit is contained in:
24
handlers/errorpage.go
Normal file
24
handlers/errorpage.go
Normal file
@@ -0,0 +1,24 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"projectreshoot/view/page"
|
||||
)
|
||||
|
||||
func ErrorPage(
|
||||
errorCode int,
|
||||
w http.ResponseWriter,
|
||||
r *http.Request,
|
||||
) {
|
||||
message := map[int]string{
|
||||
401: "You need to login to view this page.",
|
||||
403: "You do not have permission to view this page.",
|
||||
404: "The page or resource you have requested does not exist.",
|
||||
500: `An error occured on the server. Please try again, and if this
|
||||
continues to happen contact an administrator.`,
|
||||
503: "The server is currently down for maintenance and should be back soon. =)",
|
||||
}
|
||||
w.WriteHeader(http.StatusUnauthorized)
|
||||
page.Error(errorCode, http.StatusText(errorCode), message[errorCode]).
|
||||
Render(r.Context(), w)
|
||||
}
|
||||
@@ -12,11 +12,7 @@ func HandleRoot() http.Handler {
|
||||
return http.HandlerFunc(
|
||||
func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.URL.Path != "/" {
|
||||
page.Error(
|
||||
"404",
|
||||
"Page not found",
|
||||
"The page or resource you have requested does not exist",
|
||||
).Render(r.Context(), w)
|
||||
ErrorPage(http.StatusNotFound, w, r)
|
||||
return
|
||||
}
|
||||
page.Index().Render(r.Context(), w)
|
||||
|
||||
@@ -56,7 +56,7 @@ func HandleLoginRequest(
|
||||
) http.Handler {
|
||||
return http.HandlerFunc(
|
||||
func(w http.ResponseWriter, r *http.Request) {
|
||||
ctx, cancel := context.WithTimeout(r.Context(), 15*time.Second)
|
||||
ctx, cancel := context.WithTimeout(r.Context(), 10*time.Second)
|
||||
defer cancel()
|
||||
|
||||
// Start the transaction
|
||||
|
||||
Reference in New Issue
Block a user