mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-01-19 22:23:33 +01:00
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>
This commit is contained in:
parent
7572040836
commit
694d3f630e
1 changed files with 6 additions and 12 deletions
|
@ -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 a new issue