diff --git a/server/error/page.go b/server/error/page.go index 898c927..1a33b0d 100644 --- a/server/error/page.go +++ b/server/error/page.go @@ -11,9 +11,9 @@ type pageProps struct { } func Page(w http.ResponseWriter, publicMessage string, status int, err error) { + w.WriteHeader(status) if err != nil { log.Printf("%s --- %s\n", publicMessage, err) } templates.Execute(w, "error_page.gotmpl", pageProps{publicMessage}) - http.Error(w, "", http.StatusInternalServerError) } diff --git a/server/main.go b/server/main.go index 3a5f343..fd76a05 100644 --- a/server/main.go +++ b/server/main.go @@ -50,6 +50,7 @@ func main() { 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.HandleFunc("POST /logout", route.LogoutPost) + r.Html.Private.HandleFunc("GET /", routing.NotFound) r.Json.Public.HandleFunc("GET /", routing.NotFoundJson) diff --git a/server/routing/json_params.go b/server/routing/json_params.go deleted file mode 100644 index b550c51..0000000 --- a/server/routing/json_params.go +++ /dev/null @@ -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 -} diff --git a/server/routing/not_found.go b/server/routing/not_found.go index 8cba1a1..f8a6d35 100644 --- a/server/routing/not_found.go +++ b/server/routing/not_found.go @@ -2,6 +2,8 @@ package routing import ( "net/http" + + "lishwist/error" ) 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.Write([]byte(`{"GeneralError":"Not Found"}`)) } + +func NotFound(w http.ResponseWriter, r *http.Request) { + error.Page(w, "404 -- Page not found", http.StatusNotFound, nil) +}