nestjs-session
Version:
Idiomatic NestJS module for session
27 lines • 995 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.createRetriesMiddleware = createRetriesMiddleware;
const common_1 = require("@nestjs/common");
function createRetriesMiddleware(sessionMiddleware, retries, retiesStrategy = () => 0) {
return async (req, res, next) => {
let attempt = 0;
async function lookupSession(error) {
if (error) {
return next(error);
}
if (req.session !== undefined) {
return next();
}
if (attempt > retries) {
return next(new common_1.InternalServerErrorException('Cannot create session'));
}
if (attempt !== 0) {
await new Promise((r) => setTimeout(r, retiesStrategy(attempt)));
}
attempt++;
sessionMiddleware(req, res, lookupSession);
}
await lookupSession();
};
}
//# sourceMappingURL=retriesMiddleware.js.map