Apply suggestions from code review
Co-authored-by: Henry <111202+cryptix@users.noreply.github.com> use eh.Handle
This commit is contained in:
parent
0574c9a235
commit
a5f7701437
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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"
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue