add some error handing for session getting

This commit is contained in:
sentriz
2020-07-16 23:00:21 +01:00
parent f34a0b48f9
commit ab0d15982a

View File

@@ -2,6 +2,7 @@ package ctrladmin
import (
"context"
"fmt"
"net/http"
"github.com/gorilla/sessions"
@@ -11,7 +12,11 @@ import (
func (c *Controller) WithSession(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
session, _ := c.sessDB.Get(r, "gonic")
session, err := c.sessDB.Get(r, "gonic")
if err != nil {
http.Error(w, fmt.Sprintf("error getting session: %s", err), 500)
return
}
withSession := context.WithValue(r.Context(), CtxSession, session)
next.ServeHTTP(w, r.WithContext(withSession))
})