Fix: Show proper 404 if version doesn't exist.

Fix #1
main
Óscar M. Lage 2022-03-28 21:09:07 +02:00
parent dba37137ff
commit f1aef623b6
3 changed files with 10 additions and 0 deletions

View File

@ -29,6 +29,7 @@ func WikiPage(c echo.Context) error {
// If record not found, show 404
if err.Error() == "record not found" {
return c.Render(http.StatusOK, "notfound.html", map[string]interface{}{
return c.Render(http.StatusNotFound, "404.html", map[string]interface{}{
"name": page_id,
})
}

View File

@ -57,6 +57,7 @@ func Serve() {
templates["edit.html"] = template.Must(template.ParseFiles("views/edit.html", "views/base.html"))
templates["about.html"] = template.Must(template.ParseFiles("views/about.html", "views/base.html"))
templates["notfound.html"] = template.Must(template.ParseFiles("views/notfound.html", "views/base.html"))
templates["404.html"] = template.Must(template.ParseFiles("views/404.html", "views/base.html"))
e.Renderer = &TemplateRegistry{
templates: templates,
}

8
views/404.html Normal file
View File

@ -0,0 +1,8 @@
{{define "title"}}
Wikingo | {{index . "name"}}
{{end}}
{{define "body"}}
<h1>404</h1>
<h2>Page not found</h2>
{{end}}