diff --git a/web/main.go b/web/main.go index 609a3eb..d4976ef 100644 --- a/web/main.go +++ b/web/main.go @@ -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) + }) + // ----------------- // ----------------- diff --git a/web/views/404.templ b/web/views/404.templ new file mode 100644 index 0000000..85b78dd --- /dev/null +++ b/web/views/404.templ @@ -0,0 +1,9 @@ +package views + +templ NotFound() { +
+

404

+

Comfychan couldn’t find that page.

+ 404 mascot +
+}