Add basic 404 handling

This commit is contained in:
Dominic Ferrando
2025-04-24 21:50:37 -04:00
parent da518d7a12
commit e616fafc64
2 changed files with 33 additions and 4 deletions
+24 -4
View File
@@ -98,8 +98,12 @@ func main() {
board, err := database.GetBoard(db, slug)
if err != nil {
http.NotFound(w, r)
log.Printf("Board %q not found: %v", slug, err)
if errors.Is(err, sql.ErrNoRows) {
views.NotFound().Render(r.Context(), w)
return
}
http.Error(w, "Failed to get board", http.StatusInternalServerError)
log.Printf("Failed to get board%q: %v", slug, err)
return
}
@@ -118,13 +122,21 @@ func main() {
board, err := database.GetBoard(db, slug)
if err != nil {
http.NotFound(w, r)
log.Printf("Board %q not found: %v", slug, err)
if errors.Is(err, sql.ErrNoRows) {
views.NotFound().Render(r.Context(), w)
return
}
http.Error(w, "Failed to get board", http.StatusInternalServerError)
log.Printf("Failed to get board%q: %v", slug, err)
return
}
thread, err := database.GetThread(db, threadId)
if err != nil {
if errors.Is(err, sql.ErrNoRows) {
views.NotFound().Render(r.Context(), w)
return
}
http.Error(w, "Failed to get thread", http.StatusInternalServerError)
log.Printf("Failed to get thread %q: %v", threadIdStr, err)
return
@@ -464,6 +476,10 @@ func main() {
thread, err := database.GetThread(db, threadId)
if err != nil {
if errors.Is(err, sql.ErrNoRows) {
views.NotFound().Render(r.Context(), w)
return
}
http.Error(w, "Failed to get thread", http.StatusBadRequest)
log.Printf("GetThread: %v", err)
return
@@ -675,6 +691,10 @@ func main() {
})
})
r.NotFound(func(w http.ResponseWriter, r *http.Request) {
views.NotFound().Render(r.Context(), w)
})
// -----------------
// -----------------
+9
View File
@@ -0,0 +1,9 @@
package views
templ NotFound() {
<div class="container not-found">
<h1>404</h1>
<p>Comfychan couldnt find that page.</p>
<img src="/static/media/comfy-404.png" alt="404 mascot"/>
</div>
}