SessionStore: Propagate database errors to express-session
Send a 500 HTTP status code to the client if the session entry could not be fetched from the database. This is useful in case the database is busy and can't respond to the query in time. In this case we want to abort the client connection as soon as possible. Co-authored-by: Richard Hansen <rhansen@rhansen.org>pull/5106/head
parent
7572040836
commit
694d3f630e
|
@ -17,18 +17,12 @@ const logger = log4js.getLogger('SessionStore');
|
|||
module.exports = class SessionStore extends Store {
|
||||
get(sid, fn) {
|
||||
logger.debug(`GET ${sid}`);
|
||||
DB.db.get(`sessionstorage:${sid}`, (err, sess) => {
|
||||
if (sess) {
|
||||
sess.cookie.expires = ('string' === typeof sess.cookie.expires
|
||||
? new Date(sess.cookie.expires) : sess.cookie.expires);
|
||||
if (!sess.cookie.expires || new Date() < sess.cookie.expires) {
|
||||
fn(null, sess);
|
||||
} else {
|
||||
this.destroy(sid, fn);
|
||||
}
|
||||
} else {
|
||||
fn();
|
||||
}
|
||||
DB.db.get(`sessionstorage:${sid}`, (err, s) => {
|
||||
if (err != null) return fn(err);
|
||||
if (!s) return fn(null);
|
||||
if (typeof s.cookie.expires === 'string') s.cookie.expires = new Date(s.cookie.expires);
|
||||
if (s.cookie.expires && new Date() >= s.cookie.expires) return this.destroy(sid, fn);
|
||||
fn(null, s);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue