From 5045c06a78b23810ad97ae83eec3cff8dcae2d5f Mon Sep 17 00:00:00 2001 From: Mohamedh Fazal Date: Mon, 13 Mar 2017 16:28:33 +0500 Subject: [PATCH] ignore error when no session is found in database --- pgstore.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/pgstore.go b/pgstore.go index aef5747..91019cd 100644 --- a/pgstore.go +++ b/pgstore.go @@ -3,12 +3,12 @@ package pgstore import ( "database/sql" "encoding/base32" - "errors" - "fmt" "net/http" "strings" "time" + "github.com/pkg/errors" + "github.com/gorilla/securecookie" "github.com/gorilla/sessions" @@ -96,6 +96,8 @@ func (db *PGStore) New(r *http.Request, name string) (*sessions.Session, error) err = db.load(session) if err == nil { session.IsNew = false + } else if errors.Cause(err) == sql.ErrNoRows { + err = nil } } } @@ -236,8 +238,7 @@ func (db *PGStore) createSessionsTable() error { _, err := db.DbPool.Exec(stmt) if err != nil { - msg := fmt.Sprintf("Unable to create http_sessions table in the database: %s\n", err.Error()) - return errors.New(msg) + return errors.Wrapf(err, "Unable to create http_sessions table in the database") } return nil @@ -247,8 +248,7 @@ func (db *PGStore) selectOne(s *PGSession, key string) error { stmt := "SELECT id, key, data, created_on, modified_on, expires_on FROM http_sessions WHERE key = $1" err := db.DbPool.QueryRow(stmt, key).Scan(&s.ID, &s.Key, &s.Data, &s.CreatedOn, &s.ModifiedOn, &s.ExpiresOn) if err != nil { - msg := fmt.Sprintf("Unable to find session in the database: %s\n", err.Error()) - return errors.New(msg) + return errors.Wrapf(err, "Unable to find session in the database") } return nil