ignore error when no session is found in database

This commit is contained in:
Mohamedh Fazal 2017-03-13 16:28:33 +05:00
parent 68b36d681a
commit 5045c06a78
1 changed files with 6 additions and 6 deletions

View File

@ -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