Apply suggestions from code review

Co-authored-by: Henry <111202+cryptix@users.noreply.github.com>

use eh.Handle
This commit is contained in:
Alexander Cobleigh 2021-04-20 09:56:30 +02:00 committed by cblgh
parent 0574c9a235
commit a5f7701437
3 changed files with 8 additions and 7 deletions

View File

@ -115,13 +115,13 @@ func (h settingsHandler) getMember(w http.ResponseWriter, req *http.Request) *ro
func (h settingsHandler) verifyPostRequirements(w http.ResponseWriter, req *http.Request) bool {
if req.Method != "POST" {
// TODO: proper error type
h.r.Error(w, req, http.StatusBadRequest, fmt.Errorf("bad request"))
err := weberrors.ErrBadRequest{Where: "HTTP Method", Details: fmt.Errorf("expected POST not %s", req.Method)}
h.r.Error(w, req, http.StatusBadRequest, err)
return false
}
if err := req.ParseForm(); err != nil {
// TODO: proper error type
h.r.Error(w, req, http.StatusBadRequest, fmt.Errorf("bad request: %w", err))
err = weberrors.ErrBadRequest{Where: "Form data", Details: err}
h.r.Error(w, req, http.StatusBadRequest, err)
return false
}
return true

View File

@ -283,14 +283,16 @@ func New(
session, err := cookieStore.Get(req, i18n.LanguageCookieName)
if err != nil {
fmt.Errorf("cookie error? %w\n", err)
eh.Handle(w, req, http.StatusInternalServerError,err)
return
}
session.Values["lang"] = lang
err = session.Save(req, w)
if err != nil {
fmt.Errorf("we failed to save the language session cookie %w\n", err)
err = fmt.Errorf("we failed to save the language session cookie %w\n", err)
eh.Handle(w, req, http.StatusInternalServerError, err)
return
}
http.Redirect(w, req, previousRoute, http.StatusSeeOther)

View File

@ -9,7 +9,6 @@ import (
"github.com/stretchr/testify/assert"
// "github.com/ssb-ngi-pointer/go-ssb-room/roomdb"
"github.com/ssb-ngi-pointer/go-ssb-room/web/i18n"
"github.com/ssb-ngi-pointer/go-ssb-room/web/router"
)