Skip to content

Why gin-contrib/session wrapper of gorilla/sessions doesn't expose err in Get method? #298

@Ks89

Description

@Ks89

Readme file on gorilla/sessions shows that Get method returns also an error:

	import (
		"net/http"
		"github.com/gorilla/sessions"
	)

	var store = sessions.NewCookieStore([]byte(os.Getenv("SESSION_KEY")))

	func MyHandler(w http.ResponseWriter, r *http.Request) {
		// Get a session. We're ignoring the error resulted from decoding an
		// existing session: Get() always returns a session, even if empty.
		session, _ := store.Get(r, "session-name").                    // <---------- check here
		
	}

instead in this package err is logged but not returned:

func (s *session) Get(key interface{}) interface{} {
	return s.Session().Values[key]
}

func (s *session) Session() *sessions.Session {
	if s.session == nil {
		var err error
		s.session, err = s.store.Get(s.request, s.name)
		if err != nil {
			slog.Error(errorFormat,
				"err", err,
			)
		}
	}
	return s.session
}

why?
I want to intercept this error [sessions] ERROR! err="securecookie: expired timestamp" to manage it and return the proper error, but I can't.

Thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions