@sendhome/common 1.0.163 → 1.0.165
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.
|
@@ -29,7 +29,7 @@ const requireAuth = (sessionServiceUrl) => {
|
|
|
29
29
|
const payload = jsonwebtoken_1.default.verify(token, "EDWIN"
|
|
30
30
|
// process.env.JWT_KEY!
|
|
31
31
|
);
|
|
32
|
-
console.log("url", `${sessionServiceUrl}/${payload.sessionId}`);
|
|
32
|
+
console.log("session service url", `${sessionServiceUrl}/${payload.sessionId}`);
|
|
33
33
|
// Call the session service to validate the session
|
|
34
34
|
const response = yield axios_1.default.get(`${sessionServiceUrl}/${payload.sessionId}`);
|
|
35
35
|
if (response.status !== 200) {
|
|
@@ -41,7 +41,17 @@ const requireAuth = (sessionServiceUrl) => {
|
|
|
41
41
|
next();
|
|
42
42
|
}
|
|
43
43
|
catch (error) {
|
|
44
|
-
|
|
44
|
+
console.error("Error during session validation:", error);
|
|
45
|
+
// Check if error is an Axios error (e.g., network failure or service unreachable)
|
|
46
|
+
if (axios_1.default.isAxiosError(error)) {
|
|
47
|
+
res.status(500).json({ message: 'Error connecting to session service', error: error.message });
|
|
48
|
+
}
|
|
49
|
+
else if (error.name === 'JsonWebTokenError') {
|
|
50
|
+
res.status(401).json({ message: 'Invalid JWT token', error: error.message });
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
res.status(500).json({ message: 'Server error during session validation', error });
|
|
54
|
+
}
|
|
45
55
|
}
|
|
46
56
|
});
|
|
47
57
|
};
|