From 7d9dc274117b3c56c417fdb2ff272638558e1299 Mon Sep 17 00:00:00 2001 From: "Alexander \"Arav\" Andreev" Date: Sat, 27 May 2023 20:47:53 +0400 Subject: [PATCH] Replaced error pages with a new one. --- internal/http/api_guestbook_handlers.go | 6 +++--- internal/http/api_mindflow_handlers.go | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/internal/http/api_guestbook_handlers.go b/internal/http/api_guestbook_handlers.go index cac1109..7c6638e 100644 --- a/internal/http/api_guestbook_handlers.go +++ b/internal/http/api_guestbook_handlers.go @@ -28,7 +28,7 @@ func (h *GuestbookApiHandlers) New(w http.ResponseWriter, r *http.Request) { r.ParseForm() if !inmemdb.Solve(captcha.ID(r.FormValue("captcha_id")), captcha.Answer(r.FormValue("captcha_answer"))) { - ForbiddenError("Wrong answer given.", "Here's your message:"+r.FormValue("message"), w) + Error(w, http.StatusForbidden, "Wrong answer given.", "Here's your message:"+r.FormValue("message")) return } @@ -43,13 +43,13 @@ func (h *GuestbookApiHandlers) New(w http.ResponseWriter, r *http.Request) { entry, err = justguestbook.NewEntry(r.FormValue("name"), message, r.FormValue("website"), r.FormValue("hide_website") != "") if err != nil { - InternalError(err.Error(), "Here's your message:"+r.FormValue("message"), w) + Error(w, http.StatusInternalServerError, err.Error(), "Here's your message:"+r.FormValue("message")) return } } if err = h.db.NewEntry(entry); err != nil { - InternalError(err.Error(), "Here's your message:"+r.FormValue("message"), w) + Error(w, http.StatusInternalServerError, err.Error(), "Here's your message:"+r.FormValue("message")) return } diff --git a/internal/http/api_mindflow_handlers.go b/internal/http/api_mindflow_handlers.go index 589a193..60c5365 100644 --- a/internal/http/api_mindflow_handlers.go +++ b/internal/http/api_mindflow_handlers.go @@ -49,7 +49,8 @@ func (h *MindflowApiHandlers) NewPost(w http.ResponseWriter, r *http.Request) { } if err = h.db.NewPost(post); err != nil { - InternalError(err.Error(), "Title: "+r.FormValue("title")+" | Body: "+r.FormValue("body"), w) + msg := strings.Join([]string{"Title:", r.FormValue("title"), "| Body:", r.FormValue("body")}, " ") + Error(w, http.StatusInternalServerError, err.Error(), msg) return }