connect-session-knex icon indicating copy to clipboard operation
connect-session-knex copied to clipboard

Session store breaks when knex fails during its initialization

Open ondrejbudai opened this issue 6 years ago • 1 comments

When creating new knex session store it performs some database queries (i.e. checks whether session table exists). If some of these queries fail, session store is unusable, because sessionStore.ready promise is rejected and therefore store is not able to perform any more queries.

IMHO there isn't much to do when this happens, but it would be nice if this behaviour is mentioned in README. My proposed fix is to add information about sessionStore.ready promise, which can be checked for rejected status if initialization failed.

const session = require('express-session');
const KnexSessionStore = require('connect-session-knex')(session);
const sessionStore = new KnexSessionStore({ knex });
sessionStore.ready.catch((err) => {
  handleStoreError(err);
});

ondrejbudai avatar Dec 07 '18 09:12 ondrejbudai

I'd accept a PR for this.

gx0r avatar Nov 04 '19 23:11 gx0r