Return HTTP 404 response for non-active campsite’s public pages

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
This commit is contained in:
jordi fita mas 2023-08-14 11:57:33 +02:00
parent 114c6e6212
commit 8b5a45299e
1 changed files with 2 additions and 1 deletions

View File

@ -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
}