Merge pull request #24 from faxal/master
Ignore error when no session is found in database
This commit is contained in:
commit
49d6d0ff7e
12
pgstore.go
12
pgstore.go
|
@ -3,12 +3,12 @@ package pgstore
|
||||||
import (
|
import (
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"encoding/base32"
|
"encoding/base32"
|
||||||
"errors"
|
|
||||||
"fmt"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
|
||||||
"github.com/gorilla/securecookie"
|
"github.com/gorilla/securecookie"
|
||||||
"github.com/gorilla/sessions"
|
"github.com/gorilla/sessions"
|
||||||
|
|
||||||
|
@ -96,6 +96,8 @@ func (db *PGStore) New(r *http.Request, name string) (*sessions.Session, error)
|
||||||
err = db.load(session)
|
err = db.load(session)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
session.IsNew = false
|
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)
|
_, err := db.DbPool.Exec(stmt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
msg := fmt.Sprintf("Unable to create http_sessions table in the database: %s\n", err.Error())
|
return errors.Wrapf(err, "Unable to create http_sessions table in the database")
|
||||||
return errors.New(msg)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
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"
|
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)
|
err := db.DbPool.QueryRow(stmt, key).Scan(&s.ID, &s.Key, &s.Data, &s.CreatedOn, &s.ModifiedOn, &s.ExpiresOn)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
msg := fmt.Sprintf("Unable to find session in the database: %s\n", err.Error())
|
return errors.Wrapf(err, "Unable to find session in the database")
|
||||||
return errors.New(msg)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
Loading…
Reference in New Issue