Fixed error message reporting.
This commit is contained in:
parent
4387eb95dc
commit
fcdb2f3bf2
@ -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,11 +174,9 @@ 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) {
|
||||||
@ -186,11 +184,9 @@ func (h *Handlers) NotFound(w http.ResponseWriter, r *http.Request) {
|
|||||||
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 *****************************************************************/
|
||||||
|
Loading…
Reference in New Issue
Block a user