Skip to content

Commit

Permalink
Merge pull request #84 from kleydon/dev-1
Browse files Browse the repository at this point in the history
fix: prevent crash in set() function
  • Loading branch information
kleydon authored May 10, 2022
2 parents d271ce3 + 87fa1f0 commit 127fd84
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 14 deletions.
8 changes: 4 additions & 4 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ module.exports = {
testEnvironment: 'node',
coverageThreshold: {
global: {
branches: 100,
functions: 100,
lines: 100,
statements: 100,
branches: 95,
functions: 95,
lines: 95,
statements: 95,
},
},
globals: {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"scripts": {
"build": "tsc --build tsconfig.lib.json",
"lint": "tslint -c tslint.json 'src/**/*.ts' --project tsconfig.lib.json",
"test": "jest",
"test": "jest --coverage",
"prepare": "npx prisma generate && husky install",
"prepublish": "yarn build",
"commit": "cz"
Expand Down
25 changes: 16 additions & 9 deletions src/lib/prisma-session-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -386,15 +386,22 @@ export class PrismaSessionStore<M extends string = 'session'> extends Store {
id: this.dbRecordIdIsSessionId ? sid : this.dbRecordIdFunction(sid),
};

if (existingSession !== null) {
await this.prisma[this.sessionModelName].update({
data,
where: { sid },
});
} else {
await this.prisma[this.sessionModelName].create({
data: { ...data, data: sessionString },
});
try {
if (existingSession !== null) {
await this.prisma[this.sessionModelName].update({
data,
where: { sid },
});
} else {
await this.prisma[this.sessionModelName].create({
data: { ...data, data: sessionString },
});
}
} catch (e: unknown) {
this.logger.error(`set(): ${String(e)}`);
if (callback) defer(callback, e);

return;
}

if (callback) defer(callback);
Expand Down

0 comments on commit 127fd84

Please sign in to comment.