feat: page not found
This commit is contained in:
parent
b48140e9c3
commit
20761920d3
|
|
@ -11,9 +11,9 @@ type pageProps struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func Page(w http.ResponseWriter, publicMessage string, status int, err error) {
|
func Page(w http.ResponseWriter, publicMessage string, status int, err error) {
|
||||||
|
w.WriteHeader(status)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("%s --- %s\n", publicMessage, err)
|
log.Printf("%s --- %s\n", publicMessage, err)
|
||||||
}
|
}
|
||||||
templates.Execute(w, "error_page.gotmpl", pageProps{publicMessage})
|
templates.Execute(w, "error_page.gotmpl", pageProps{publicMessage})
|
||||||
http.Error(w, "", http.StatusInternalServerError)
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -50,6 +50,7 @@ func main() {
|
||||||
r.Html.Private.Handle("POST /list/{userReference}", route.ExpectUser(route.ForeignWishlistPost))
|
r.Html.Private.Handle("POST /list/{userReference}", route.ExpectUser(route.ForeignWishlistPost))
|
||||||
r.Html.Private.Handle("GET /group/{groupReference}", route.ExpectUser(route.GroupPage))
|
r.Html.Private.Handle("GET /group/{groupReference}", route.ExpectUser(route.GroupPage))
|
||||||
r.Html.Private.HandleFunc("POST /logout", route.LogoutPost)
|
r.Html.Private.HandleFunc("POST /logout", route.LogoutPost)
|
||||||
|
r.Html.Private.HandleFunc("GET /", routing.NotFound)
|
||||||
|
|
||||||
r.Json.Public.HandleFunc("GET /", routing.NotFoundJson)
|
r.Json.Public.HandleFunc("GET /", routing.NotFoundJson)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,13 +0,0 @@
|
||||||
package routing
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
"net/http"
|
|
||||||
)
|
|
||||||
|
|
||||||
func decodeJsonParams(r *http.Request, v any) error {
|
|
||||||
dec := json.NewDecoder(r.Body)
|
|
||||||
dec.DisallowUnknownFields()
|
|
||||||
err := dec.Decode(&v)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
@ -2,6 +2,8 @@ package routing
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"lishwist/error"
|
||||||
)
|
)
|
||||||
|
|
||||||
func NotFoundJson(w http.ResponseWriter, r *http.Request) {
|
func NotFoundJson(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
@ -9,3 +11,7 @@ func NotFoundJson(w http.ResponseWriter, r *http.Request) {
|
||||||
w.WriteHeader(http.StatusNotFound)
|
w.WriteHeader(http.StatusNotFound)
|
||||||
_, _ = w.Write([]byte(`{"GeneralError":"Not Found"}`))
|
_, _ = w.Write([]byte(`{"GeneralError":"Not Found"}`))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func NotFound(w http.ResponseWriter, r *http.Request) {
|
||||||
|
error.Page(w, "404 -- Page not found", http.StatusNotFound, nil)
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue