1
0

Fixed error message reporting.

This commit is contained in:
Alexander Andreev 2023-02-06 00:02:13 +04:00
parent 4387eb95dc
commit fcdb2f3bf2
Signed by: Arav
GPG Key ID: 0388CC8FAA51063F

View File

@ -135,7 +135,7 @@ func (h *Handlers) GuestbookPost(w http.ResponseWriter, r *http.Request) {
r.ParseForm() r.ParseForm()
if !inmemdb.Solve(captcha.ID(r.FormValue("captcha_id")), captcha.Answer(r.FormValue("captcha_answer"))) { if !inmemdb.Solve(captcha.ID(r.FormValue("captcha_id")), captcha.Answer(r.FormValue("captcha_answer"))) {
h.ForbiddenError("wrong answer", "Here's your message:"+r.FormValue("message")) h.ForbiddenError("Wrong answer given.", "Here's your message:"+r.FormValue("message"), w)
return return
} }
@ -146,14 +146,14 @@ func (h *Handlers) GuestbookPost(w http.ResponseWriter, r *http.Request) {
entry, err = guestbook.NewEntry(r.FormValue("name"), r.FormValue("message"), entry, err = guestbook.NewEntry(r.FormValue("name"), r.FormValue("message"),
r.FormValue("website"), r.FormValue("hide_website") != "") r.FormValue("website"), r.FormValue("hide_website") != "")
if err != nil { if err != nil {
h.InternalError(err.Error(), "Here's your message:"+r.FormValue("message")) h.InternalError(err.Error(), "Here's your message:"+r.FormValue("message"), w)
return return
} }
} }
if err = h.guestbookDB.NewEntry(entry); err != nil { if err = h.guestbookDB.NewEntry(entry); err != nil {
h.InternalError(err.Error(), "Here's your message:"+r.FormValue("message")) h.InternalError(err.Error(), "Here's your message:"+r.FormValue("message"), w)
return return
} }
@ -174,24 +174,20 @@ func (h *Handlers) Robots(w http.ResponseWriter, r *http.Request) {
/**** Errors ******************************************************************/ /**** Errors ******************************************************************/
func (h *Handlers) ForbiddenError(err, msg string) func(http.ResponseWriter, *http.Request) { func (h *Handlers) ForbiddenError(err, msg string, w http.ResponseWriter) {
return func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusForbidden) w.WriteHeader(http.StatusForbidden)
web.ForbiddenError("/ Forbidden", err, msg, w) web.ForbiddenError("/ Forbidden", err, msg, w)
} }
}
func (h *Handlers) NotFound(w http.ResponseWriter, r *http.Request) { func (h *Handlers) NotFound(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusNotFound) w.WriteHeader(http.StatusNotFound)
web.NotFound("Not Found", w) web.NotFound("Not Found", w)
} }
func (h *Handlers) InternalError(err, msg string) func(http.ResponseWriter, *http.Request) { func (h *Handlers) InternalError(err, msg string, w http.ResponseWriter) {
return func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusInternalServerError) w.WriteHeader(http.StatusInternalServerError)
web.InternalError("/ Internal Error", err, msg, w) web.InternalError("/ Internal Error", err, msg, w)
} }
}
/**** CAPTCHA *****************************************************************/ /**** CAPTCHA *****************************************************************/