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()
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
}
@ -146,14 +146,14 @@ func (h *Handlers) GuestbookPost(w http.ResponseWriter, r *http.Request) {
entry, err = guestbook.NewEntry(r.FormValue("name"), r.FormValue("message"),
r.FormValue("website"), r.FormValue("hide_website") != "")
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
}
}
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
}
@ -174,11 +174,9 @@ func (h *Handlers) Robots(w http.ResponseWriter, r *http.Request) {
/**** Errors ******************************************************************/
func (h *Handlers) ForbiddenError(err, msg string) func(http.ResponseWriter, *http.Request) {
return func(w http.ResponseWriter, r *http.Request) {
func (h *Handlers) ForbiddenError(err, msg string, w http.ResponseWriter) {
w.WriteHeader(http.StatusForbidden)
web.ForbiddenError("/ Forbidden", err, msg, w)
}
}
func (h *Handlers) NotFound(w http.ResponseWriter, r *http.Request) {
@ -186,11 +184,9 @@ func (h *Handlers) NotFound(w http.ResponseWriter, r *http.Request) {
web.NotFound("Not Found", w)
}
func (h *Handlers) InternalError(err, msg string) func(http.ResponseWriter, *http.Request) {
return func(w http.ResponseWriter, r *http.Request) {
func (h *Handlers) InternalError(err, msg string, w http.ResponseWriter) {
w.WriteHeader(http.StatusInternalServerError)
web.InternalError("/ Internal Error", err, msg, w)
}
}
/**** CAPTCHA *****************************************************************/