From 8b5a45299e59a6d4f4e73b765103023f42d1a201 Mon Sep 17 00:00:00 2001 From: jordi fita mas Date: Mon, 14 Aug 2023 11:57:33 +0200 Subject: [PATCH] =?UTF-8?q?Return=20HTTP=C2=A0404=20response=20for=20non-a?= =?UTF-8?q?ctive=20campsite=E2=80=99s=20public=20pages?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit At first i thought i had to return HTTP 410 gone in this case, but HTTP Semantics RFC[0] says that “The 410 (Gone) status code indicates that […] this condition is likely to be permanent. If the origin server does not know […] whether or not the condition is permanent, the status code 404 (Not Found) ought to be used instead.” A non-active campsite type does not mean “deleted”, but rather temporarily disabled, thus a 404 is the appropriate code. [0] https://www.rfc-editor.org/rfc/rfc9110#status.410 --- pkg/campsite/types/public.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pkg/campsite/types/public.go b/pkg/campsite/types/public.go index caa266b..01939ba 100644 --- a/pkg/campsite/types/public.go +++ b/pkg/campsite/types/public.go @@ -34,6 +34,7 @@ func (h *PublicHandler) Handler(user *auth.User, company *auth.Company, conn *da page, err := newPublicPage(r.Context(), conn, head) if database.ErrorIsNotFound(err) { http.NotFound(w, r) + return } else if err != nil { panic(err) } @@ -54,7 +55,7 @@ func newPublicPage(ctx context.Context, conn *database.Conn, slug string) (*publ page := &publicPage{ PublicPage: template.NewPublicPage(), } - row := conn.QueryRow(ctx, "select name, description::text from campsite_type where slug = $1", slug) + row := conn.QueryRow(ctx, "select name, description::text from campsite_type where slug = $1 and active", slug) if err := row.Scan(&page.Name, &page.Description); err != nil { return nil, err }