@ladjs/web 14.0.9 → 15.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +20 -12
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -344,15 +344,22 @@ class Web {
|
|
|
344
344
|
|
|
345
345
|
// session store
|
|
346
346
|
app.keys = this.config.sessionKeys;
|
|
347
|
-
app.use(
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
347
|
+
app.use(async (ctx, next) => {
|
|
348
|
+
try {
|
|
349
|
+
await session({
|
|
350
|
+
store: redisStore({ client: this.client }),
|
|
351
|
+
key: this.config.cookiesKey,
|
|
352
|
+
cookie: this.config.cookies,
|
|
353
|
+
genSid: this.config.genSid,
|
|
354
|
+
...this.config.session
|
|
355
|
+
})(ctx, () => Promise.resolve());
|
|
356
|
+
} catch (err) {
|
|
357
|
+
// this would indicate that redis is down
|
|
358
|
+
ctx.logger.error(err);
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
return next();
|
|
362
|
+
});
|
|
356
363
|
|
|
357
364
|
// redirect loop (must come after sessions added)
|
|
358
365
|
if (this.config.redirectLoop) {
|
|
@@ -400,11 +407,12 @@ class Web {
|
|
|
400
407
|
try {
|
|
401
408
|
await csrf(ctx, next);
|
|
402
409
|
} catch (err) {
|
|
410
|
+
ctx.logger.error(err);
|
|
403
411
|
let error = err;
|
|
404
|
-
|
|
412
|
+
// this would indicate that redis is down
|
|
413
|
+
if (!ctx.session) error = Boom.clientTimeout();
|
|
414
|
+
else if (err.name && err.name === 'ForbiddenError')
|
|
405
415
|
error = Boom.forbidden(err.message);
|
|
406
|
-
if (err.stack) error.stack = err.stack;
|
|
407
|
-
}
|
|
408
416
|
|
|
409
417
|
ctx.throw(error);
|
|
410
418
|
}
|
package/package.json
CHANGED