Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Henry <[email protected]>

use eh.Handle
  • Loading branch information
cblgh committed Apr 20, 2021
1 parent 0574c9a commit a5f7701
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
8 changes: 4 additions & 4 deletions web/handlers/admin/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions web/handlers/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion web/handlers/set_language_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down

0 comments on commit a5f7701

Please sign in to comment.