add some error handing for session getting
This commit is contained in:
@@ -2,6 +2,7 @@ package ctrladmin
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/gorilla/sessions"
|
"github.com/gorilla/sessions"
|
||||||
@@ -11,7 +12,11 @@ import (
|
|||||||
|
|
||||||
func (c *Controller) WithSession(next http.Handler) http.Handler {
|
func (c *Controller) WithSession(next http.Handler) http.Handler {
|
||||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
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)
|
withSession := context.WithValue(r.Context(), CtxSession, session)
|
||||||
next.ServeHTTP(w, r.WithContext(withSession))
|
next.ServeHTTP(w, r.WithContext(withSession))
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user