diff --git a/internal/handlers/handlers.go b/internal/handlers/handlers.go index 5ff9e32..5a1b910 100644 --- a/internal/handlers/handlers.go +++ b/internal/handlers/handlers.go @@ -2,6 +2,7 @@ package handlers import ( "encoding/json" + "fmt" "justguestbook/internal/guestbook" "justguestbook/pkg/justcaptcha" "justguestbook/pkg/server" @@ -52,6 +53,8 @@ func (h *GuestbookHandlers) Entries(w http.ResponseWriter, r *http.Request) { entries, err := h.db.Entries(page_num, page_size) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) + log.Println("failed to retrieve entries:", err) + return } guestbookEntries := struct { @@ -62,7 +65,10 @@ func (h *GuestbookHandlers) Entries(w http.ResponseWriter, r *http.Request) { Entries: entries} w.Header().Add("Content-Type", "application/json") - json.NewEncoder(w).Encode(&guestbookEntries) + if err := json.NewEncoder(w).Encode(&guestbookEntries); err != nil { + log.Println("failed to encode entries:", err) + http.Error(w, fmt.Sprintln("failed to encode entries:", err.Error()), http.StatusInternalServerError) + } } func (h *GuestbookHandlers) New(w http.ResponseWriter, r *http.Request) {